using (DB.HZJY_CGOAContext myContext = new DB.HZJY_CGOAContext())
                {
                    var context = myContext.Busi_ProjectStandItem;
                    foreach (DB.Busi_ProjectStandItem psdelmodel in listDelProjectStandItem)
                    {
                        context.Remove(curmodel);
                    }
                    foreach (DB.Busi_ProjectStandItem psaddmodel in listAddProjectStandItem)
                    {
                        context.Add(psaddmodel);
                    }
                    myContext.Entry(model).State = EntityState.Modified;
                    myContext.SaveChanges();
                    _nResult = 1;
                }

 

解决办法

 using (DB.HZJY_CGOAContext myContext = new DB.HZJY_CGOAContext())
                {
                    var context = myContext.Busi_ProjectStandItem;
                    foreach (DB.Busi_ProjectStandItem psdelmodel in listDelProjectStandItem)
                    {

        
                        var curmodel=myContext.Busi_ProjectStandItem.Attach(psdelmodel);
                        context.Remove(curmodel);
                    }
                    foreach (DB.Busi_ProjectStandItem psaddmodel in listAddProjectStandItem)
                    {
                        context.Add(psaddmodel);
                    }
                    myContext.Entry(model).State = EntityState.Modified;
                    myContext.SaveChanges();
                    _nResult = 1;
                }

posted on 2013-01-23 15:53  Berthing  阅读(1726)  评论(0)    收藏  举报