告诉 EF 不要考虑位字段 = 1 (isDeleted) 的记录
所有表都有一个位字段 IsDeleted
有没有办法告诉 EF 在执行查询时不要考虑它们。
或者我只需每次都指定一下 Where(o => o.IsDeleted != true)
(首先使用 EF4 CTP5 代码)
all tables have a bit field IsDeleted
is there a way to tell EF not to consider them when doing queries.
or I just have to specify this each time like Where(o => o.IsDeleted != true)
(using EF4 CTP5 code first)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过在通用存储库中执行此操作解决了这个问题,我还为没有 isDeleted 的实体创建了一个只读存储库(它们根本不由应用程序管理,只是读取),只读存储库获取所有
记录simple repo 继承了 readonly 并重写了不应该返回标有 isDeleted = false 的实体的方法;
应该标记为 IsDeleted = true 的实体从 DelEntity 继承
我的通用存储库:
我的只读操作存储库
此解决方案有点特定于我的情况,但希望您可以从中得到一些想法
I solved this by doing this in my generic repository, I also made a readonly repository for entities that don't have the isDeleted (they aren't managed by the app at all, just reading), the readonly repo gets all the records
the simple repo inherits the readonly one and overrides the methods that should not return entities marked with isDeleted = false;
entities that should be just marked IsDeleted = true inherit from DelEntity
my generic repository:
my repository for readonly operations
this solution it's a bit specific to my case, but hopefully you might get some ideas from it