We\'re having some issues implementing soft delete functionality with entity framework. The idea is to use a repository which is aware of the EF context. On the level of the
Yes, using ExpressionVisitor
is the correct approach.
You need to transform x.Bonus
into x.Bonus.Where(x => !x.IsDeleted)
. I suggest you do the same thing for x.Bonus.Where(y => y.bonID == 100)
. Transform it into x.Bonus.Where(x => !x.IsDeleted).Where(y => y.bonID == 100)
This means that you need to convert any Expression of type IQueryable<Bonus>
to another expression of type IQueryable<Bonus>
, but with the where-clause appended.
You probably need to override the very general ExpressionVisitor.Visit
method to visit all expressions, not just binary ones.
You are very likely to run into special cases here that you haven't thought about yet. This is going to be difficult, but fun :)
Victory! Today I've created an ExpressionVisitor which appends IsDeleted where clause to each select, even in navigation properties!