6
votes

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

3

3 Answers

5
votes
0
votes

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.

0
votes

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