日期:2014-05-18  浏览次数:20405 次

Linq to Entities 一对多外键关联 添加数据报错?
ActilceT At = new ActilceT();
  At.ActicleContent = "ss";
  At.ActilceListT.ActilceListID = 1;//这行报错未将对象引用到实例;ActilceListID是ActilceT表的外键,ActilceListT是主表,
  using (E_dbEntities db = new E_dbEntities())
  {
  db.AddToActilceT(At);
  db.SaveChanges();
  }

------解决方案--------------------
探讨
ActilceT At = new ActilceT();
At.ActicleContent = "ss";
At.ActilceListT.ActilceListID = 1;//这行报错未将对象引用到实例;ActilceListID是ActilceT表的外键,ActilceListT是主表,
using (E_dbEntities db = new E_dbEntities……

------解决方案--------------------
At.ActilceListT=new 类型;
At.ActilceListT.ActilceListID = 1;