开发者

Entity Framework and soft deleted records

开发者 https://www.devze.com 2022-12-10 06:20 出处:网络
I\'m developing WCF service which is u开发者_开发技巧sing entity framework as data source. Almost all is ok except problem with deleted records. In our database we\'re using soft delete (mark record a

I'm developing WCF service which is u开发者_开发技巧sing entity framework as data source. Almost all is ok except problem with deleted records. In our database we're using soft delete (mark record attribute IsDeleted = true). My question how to exclude soft deleted records from entity set?

For example, entity "A" has entity set "Bs" (FK to table "B"). How to make that "Bs" entity set only contains from records which is not deleted?

Thank you


I have written a post about this topic, hope it helps.

http://blog.jorgef.net/2010/12/ef-soft-delete.html


One way would be to use a defining query. But we typically handle this in the Repository, since we actually do want to materialize "soft deleted" entities in rare cases.


You could map you EF entities to views instead of tables

CREATE VIEW vw_Currency AS
SELECT 
    *   
FROM 
    Currency c 
WHERE 
    c.IsAKDeleted=0

I have worked on a system which used this approach but it was not based on EF. I have not tried it with EF

0

精彩评论

暂无评论...
验证码 换一张
取 消