Entity Framework 6 - Map only one statement to Stored Procedure

c# entity-framework entity-framework-6

Question

This is how I'm mapping an entity to insert into a stored procedure:

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

When I save a new member, the insert works perfectly and sends all parameters to the saved method.

But I get an exception because it's seeking for a stored procedure named "update" when I try to change a member (loading entity from database by id, altering its properties, then saving again - what will issue the update statement).Member_Update .

However, I don't want to have stored processes for that (or for remove). Just a stored procedure for the insert statement will do.

Can I link the insert action just in EF to a stored procedure?

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

Popular Answer

It's sadly all or nothing.

Documentation for Entity Framework:

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