Stored procedures not called in Entity framework using asp.net MVC -


I am trying to use the process mapping feature stored in the unit framework for updating and deleting functions.

For whatever reason processes are not being called, they are mapped correctly, and it is believed that what I have to do is call SaveChanges (); is in my controller to execute.

When using as a reference, what will I change about it? To edit the part of the controller, is it to use the stored procedure?

Tutorial Code:

  // gET: / home / edit / edit 5 public functioning (int id) {var contact edit = (c to _entities. ContactSet where c.Id == ID select c) .FirstOrDefault (); See return (contactToEdit); } // // Post: / home / edit / 5 [accept wirbes (httpv.bbs.post)] edit public action result (contact contact) {if (! ModelState.ISIIIDID) return see (); Try {var originalContact = (c to _entities.ContactSet), select c.Id == contactToEdit.Id c) .FirstOrDefault (); _entities.ApplyPropertyChanges (basic dialogue.AntityKey.EntitySetName, contactToEdit); _entities.SaveChanges (); Return Redirect Action ("Index"); } Hold {return (see); }}}  

I thought just by calling SaveChanges (); Update sproc will be updated, so I removed the call ApplyPropertyChanges (); As::

// // Post: / Home / Edit / 5 [Accept Works (HTTPVersBobs.post)] Edit Public Functionality (Contact Contact) {Return (ModelState IsValid) Return View (); Try {_entities.SaveChanges (); Return Redirect Action ("Index"); } Hold {return (see); }}}

Although the update does not execute the stored procedure, I'm sure SQL Running sqiler is running.

Programming Entity Framework The book tutorial is quoted as saying:

Now stored procedures are mapped, Calling in is not necessary at any time called SaveChanges, the unit framework will use your mapped stored procedures for any necessary insert, update, and delete.

So, I think that something is quite obvious to me. >

Edit, here is the exact version that I am now working with, the names are different:

  // gET: / candidate / edit / edit 5 public functions (Int id) {var candidateToEdit = (Internships in C from Integrate where c.UserID == ID select c) .FirstOrDefault (); // View Data ["Education ID"] = New Selection List (Internship Education List, "ID", "Category", Ed. Education Education for the Candidate); See Return (for Candidate)} // // Post: / Candidate / Edit / 5 [Acceptable Viebers (HTVRbS.post)] Public Action Result Edit (FullCandidate Appointment Taxidit) {If (ModelState.Is.I.D. ); {Var originalCandidate = (Try internship in C. Please complete where C. USIDID == select candidate TōEdit.UserID c). FirstOrDefault (); an internship. Appreciate Change (Original Candidate Antitiki. Antitissant Name, for Candidate); Internship.SaveChanges (); Return Redirect Action ("Index"); } Hold (exception e) {Response.Write ("Error:" + E); // Return View (); Return tap; }}}}  

It looks almost identical to the tutorial code in the structure but throws an NullReference exception at runtime.

The problem with your example is that the contact unit has been received as a parameter from the data reference This is not connected when called SaveChanges, there is nothing to update. Normally on the update, I use the provided ID and I get the original unit from the database and apply the changes. When you do this, SaveChanges should move its stored procedure to the unit with its change.

To retrieve the original unit, revert to the code and apply the change to it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -