Reputation:
I'm developing WCF service which is using 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
Upvotes: 6
Views: 3066
Reputation: 3504
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
Upvotes: 0
Reputation: 457
I have written a post about this topic, hope it helps.
http://blog.jorgef.net/2010/12/ef-soft-delete.html
Upvotes: 5
Reputation: 126547
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.
Upvotes: 0