ExpressionVisitor soft delete

一笑奈何 提交于 2019-11-28 11:46:50

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!