-
Notifications
You must be signed in to change notification settings - Fork 170
Open
Description
Thanks for the good book. It helps a lot in the study of EF Core.
In one place it seemed to me that the code could be simplified. Maybe my proposal will come in handy for you for the next publication of the book.
File: DataLayer/EfCode/SoftDeleteQueryExtensions.cs
public static void AddSoftDeleteQueryFilter(
this IMutableEntityType entityData,
MyQueryFilterTypes queryFilterType,
IUserId userIdProvider = null)
{
switch (queryFilterType) {
case MyQueryFilterTypes.SoftDelete:
entityData.SetQueryFilter((Expression<Func<ISoftDelete,bool>>)(x => !x.SoftDeleted));
entityData.AddIndex(entityData.FindProperty(nameof(ISoftDelete.SoftDeleted)));
break;
case MyQueryFilterTypes.UserId:
entityData.SetQueryFilter((Expression<Func<IUserId,bool>>)(x => x.UserId == userIdProvider.UserId));
entityData.AddIndex(entityData.FindProperty(nameof(IUserId.UserId)));
break;
}
}
P.s. To complete the picture, can an index should add a call .SetFilter("[SoftDeleted] = 0")?
P.p.s. I didn't test my code
Metadata
Metadata
Assignees
Labels
No labels