I have some entities that have a IsDeleted
(logic delete) property and when I do queries, the standard would be to return all but deleted ones, like:
var query = collection.Where(e=> !e.IsDeleted);
I'm using predicate builder to create some predicates for reuse, so I have a search like this :
public static Func<FakeEntity, bool> ContainsName(string keyword) {
var predicate = NotDeleted();
predicate = predicate.And(e => e.Name.Contains(keyword));
return predicate;
}
and a NotDeleted()
predicate :
public static Func<FakeEntity, bool> NotDeleted() {
var predicate = PredicateBuilderDelegate.True<FakeEntity>();
predicate = predicate.And(e => !e.IsDeleted);
return predicate;
}
what I want is to create another predicate that 'overrides' some how the NotDeleted()
one, so in code I can call :
var result = collection.Where(FakeEntity.ContainsName("keyword")
.And(FakeEntity.IncludeDeleted()));
The idea beyond that is when I use the ContainsName
it returns all entities that contains that string that are not deleted, but I want some way to explicitly say to include those deleted ones.
Is it clear?
What I tryied with no luck is :
public static Func<FakeEntity, bool> IncludeDeleted() {
var predicate = PredicateBuilderDelegate.True<FakeEntity>();
predicate = predicate.And(e => e.IsDeleted);
return predicate;
}