无法更新关系表数据

时间:2015-07-15 08:20:45

标签: c# entity-framework-6

  public bool UpdateBlockDetails(Block_updateblock)          
       {             
        using (var context = new DbContext())              
         {               
           context.Blocks.Attach(_updateblock);                
           context.Entry(_updatejoc).State = System.Data.Entity.EntityState.Modified; 
           context.SaveChanges();        
         }
        return true;
    }

===========================

public bool UpdateBlockDetails(Block _updateblock)
      {
         using (var context = new DbContext())
        {
            var joc = context.Blocks.SingleOrDefault(x => x.ID == _updateblock.ID);
            if (block == null)
            {
                return false;
            }
            else
            {
                Block.Name = _updatejoc.Name;
                Block.Address = _updateblock.Address;
                Block.IsActive = _updateblock.IsActive;
                Block.StakeHolders = null;
                foreach (var sh in _updateblock.StakeHolders)
                {                        
                    joc.StakeHolders.Add(sh);
                }
                context.SaveChanges();
            }              
            return true;
        }
    }

问题:我无法更新。我尝试了这两种方法来更新块但没有成功。 Block与利益相关者的关系为1对多。

0 个答案:

没有答案