asp.net mvc - Merge an Object that wen outside the datacontext -
I have the following question: It is easy to insert an oBject in the database with a form.
Public Static Zero AddPage (string string, page page) {using (var db = new CardReaderDataContext ()) {page.Lang = lang; Page. URL = UrlHelper.CreateValidSeoUrl (PageName, "-"); Db.Pages.InsertOnSubmit (page); Db.SubmitChanges (); }}
But if you want to update an object, then this is a daunting task. You do the same flow,
- You get the object,
- Link it to your form,
- Post it, but now! !! Because it has exited your datacontext, you have to reload the object from the datacontext,
- To move and save all the variables, this is a bit complicated explained, so I give an example
To update an object that you have modified in one form:
public static void Update (page page) {(var db = new CardReaderDataContext (using)) {Var _page = Db.Pages.Where (p = & gt; p.Guid == page.Guid). Single (); _page.ModificationDate = DateTime.Now; _page.Title = Page. Title; _page.Description = page.Description; _page.Content = page.Content; _page.Keywords = Page. Keywords; _page.Name = Page Name; _page.WTLang = page.WTLang; _page.WTSKU = Page WTSKU; _page.WTTi = Page TTI; _page.WTUri = Page TURI; _page.URL = UrlHelper.CreateValidSeoUrl (PageName, "-"); // _page.Order = GetMaxOrderByMenuGuid (PageMenuGuid); Db.SubmitChanges (); }}
I do not know if it is clear, if this is not my comment, then I
I think you can get data contentx. Looking for attachments, but you can use only those LCDs that have been serialized / deserialized.
Read one answer to this question -
"There is no good idea to try to bring an older version, by doing so you are discontinuing optimistic concurrency. So, unless you do this, this is a bad way. What you should do is the journey of the goal in both the original position and the current state of the object. "
Comments
Post a Comment