stored procedures - Database gets updated before SaveChanges is called in Entity Framework -


i trying use ef insert stored procedure as have no direct access table. understanding database should not updated until savechanges() called in code database updated insert happens. in case, 4 database calls made.

how make have 1 database call , update multiple records?

this may classed database-first ef? stored procedure imported function edmx in normal way.

code sample:

public actionresult index() {         list<product> products = new list<product> {             new product() { title = "coca cola", description = "good"},             new product() { title = "apple", description = "fruit"},             new product() { title = "orange", description = "fruit"},             new product() { title = "banana", description = "my favourite"}         };          efwithsptest context = new efwithsptest();          foreach(var p in products)         {             context.insert(p.title, p.description);         }          context.savechanges();          return view();     }  

stored procedure:

alter procedure [dbo].[insert] @title nvarchar (50), @description nvarchar (max) insert [product] (title, description) values (@title, @description) return 0 

auto generated dbcontext class:

public partial class efwithsptest : dbcontext {     public efwithsptest()         : base("name=entities")     {     }      protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         throw new unintentionalcodefirstexception();     }       public virtual int insert(string title, string description)     {         var titleparameter = title != null ?             new objectparameter("title", title) :             new objectparameter("title", typeof(string));          var descriptionparameter = description != null ?             new objectparameter("description", description) :             new objectparameter("description", typeof(string));          return ((iobjectcontextadapter)this).objectcontext.executefunction("insert", titleparameter, descriptionparameter);     } } 


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -