I have to implement soft delete using entitty framework.
- My DB tables have a bit column
IsDeleted. - Corresponding Entities also have
IsDeletedfield. - When a user deletes a child entity,
IsDeletedin Set to true for that child object and gets persisted well. - While loading the entity-object graph, I want to ensure that all the relevant entities get loaded with a condition
IsDeleted= false. - It tried using help from the following link, but I am getting lot of error : handling-logical-delete-with-entity-framework-4.
Here is the error I get for each entity :
error 3032: Problem in mapping fragments starting at line 38:Condition member with a condition other than ‘IsNull=False’ is mapped. Either remove the condition on EntityHavingClause.IsDeleted or remove it from the mapping.
Q: Can anyone please tell where I am going wrong and what would be the simplest way to load all child entitties whose IsDelete = false?
You mapped
EntityHavingClause.IsDeletedas a property and as a condition. You cannot do both.When you follow the example you linked to, you should not need the property mapping.
Edit:
As you need both, the property and the condition, probably the best way to go is add a calculated column to your database table that just displays the value of IsDeleted (if you can change the schema, that is). Then map the condition against the calculated column.
I think that is easier than trying to hack EF to map the same column twice (if it can be done at all).