I got the error
Cannot find the InsertFunctionMapping for EntityType 'xxx' in the mapping file.
Which is fair enough because it is true. But that is because I am happy with EF doing inserts for me. I simply want to override the delete function.
I thought that was one of the improvements with EF4? Or is it just that it will build fine but still cry when you use the unmapped functions? Or is it possible but I am just missing something?
AFAIK. It's all or nothing.
If you do not map all three of the insert, update, or delete operations of a entity type to stored procedures, the unmapped operations will fail if executed at runtime and an UpdateException is thrown.
MSDN
I have the same or similar problem. I want to override only delete function, but it is not possible in EF4 without overriding also insert and update functions. In my case I need to do this action for delete:
update table set deleted = 1 where id = @id
I solved this by this way:
Before calling the method context.SaveChanges(true)
I run this code
foreach (ObjectStateEntry entry in context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
{
entry.ChangeState(EntityState.Modified);
entry.Entity.GetType().GetProperty("deleted").SetValue(entry.Entity, true, null);
}
I'm beginner in EF. Now I only looking for how to solve some problems with EF which I have to solve before I start to develop application based on EF. But now it looks like that this solution should work. I hope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With