实体框架,软删除和查询 [英] Entity Framework, soft-deleting and queries

查看:126
本文介绍了实体框架,软删除和查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,这里是我的情况:

So here's my situation:

我是软删除表中的某些行,使用请将isDeleted 标志,使能保持我的归档数据的痕迹。我通过重写的SaveChanges 语句做的,所以我的的ObjectContext

I'm soft-deleting some rows in a table, using a IsDeleted flag, so that a can keep a trace of my archived data. I do so by overriding the SaveChanges statement in my ObjectContext.

现在的问题是:我怎么可以只选择行(S)有请将isDeleted ==虚假,而不必指定&放大器;&放; !请将isDeleted 在每一个疑问?

The question is: how can I select only the row(s) that have IsDeleted == false, without having to specify && !IsDeleted in every queries?

有没有我可以直接在我的上下文指定一个办法解决?

Is there a way I can specify this on my context directly?

TKX!

推荐答案

您可以在您的表和查询视图,而不是定义视图:

You could define a view over your table and query that view instead:

CREATE VIEW dbo.ActiveData
AS
  SELECT (list of columns)
  FROM dbo.YourTable
  WHERE IsDeleted = 0

然后在您的EDMX模式,从 ActiveData 视图,而不是基表中读取数据。

And then in your EDMX model, read your data from the ActiveData view instead of the base table.

这篇关于实体框架,软删除和查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆