Thursday, 10 May 2012

entity framework one to many  editing quirks


while editing ur one to many thingy


dont forget this.. in this case the many thingy is theColumn... devs will get it...otherwise umm  the  collection isnt updated....there is no need for this in  case of  a similar operation when it comes to create though...whatever....


  if (ModelState.IsValid)
            {
             
                context.Entry(pseudosharepointview).State = EntityState.Modified;

                 ///important!!!!!!!!!achtung!!!!!!!!!!!!!!
                foreach (SharepointColumn theColumn in pseudosharepointview.SharepointColumns)
                {

                        context.Entry(theColumn).State = EntityState.Modified;
                       // context.SaveChanges(); noob operation :D
                 
                }

                context.SaveChanges();
                return RedirectToAction("Index");
            }

No comments:

Post a Comment