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.

  • Create a single object
  • Link it to your field
  • Post back to the controller,
  • Create and datacontext datacentext. Insert Onbesmate (Object)
  •   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,

    1. You get the object,
    2. Link it to your form,
    3. Post it, but now! !! Because it has exited your datacontext, you have to reload the object from the datacontext,
    4. 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

    Popular posts from this blog

    c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

    Calling GetGUIThreadInfo from Outlook VBA -

    Obfuscating Python code? -