Entity Framework 6 - Map only one statement to Stored Procedure

c# entity-framework entity-framework-6

Question

I am mapping an entity to insert to stored procedure like this:

modelBuilder  
  .Entity<Member>()  
  .MapToStoredProcedures(s =>  
       s.Insert(u => u.HasName("stp_insert_member")));

The insert works great and passes all parameters to the stored procedure when I save new member.

But what happens when I try to update a member (loading entity from db by id, changing it's properties, and saving again - what will issue the update statement) is I get an exception because it's looking for stored procedure named Member_Update.

But for that (and for delete), I don't want to have stored procedures. I just want to execute a stored procedure for the insert statement.

Can I map EF to a stored procedure for just the insert action?

1
4
12/10/2014 7:29:05 AM

Popular Answer

Sadly it's all or nothing.

Entity Framework - Documentation:

You cannot use a mixture of stored procedures and direct table access for a given entity (or entity hierarchy). The insert, update and delete operations must all use direct table access or stored procedures.

2
5/23/2016 4:52:49 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow