据我了解,要添加子行,您可以这样做
父.子.添加(子);
或者
孩子.父母=父母
然后你可以做 myContext.SaveChanges();
不知何故,第二种解决方案根本不做插入工作。这是我的代码:
CountMaster countMaster = (from b in pMDataContext.CountMasters
where b.ReportDate == reportDate && b.Department == dept
select b).SingleOrDefault();
CountDetail countDetail = new CountDetail { CategoryId = 1, StatusId = 1 };
//countMaster.CountDetails.Add(countDetail);
countDetail.CountMaster = countMaster;
pMDataContext.SaveChanges();