如果需要为 1-1 关系添加新行,是否需要指定 Add 或 Attach?如果需要,我该怎么做?
//one tblContent to one tblContentData
//updating the tblContentData corresponding to a particular id in tblContent
int id = 12345;
tblContent entity = db.tblContents.Where(con => con.id == id)
.FirstOrDefault();
if (entity == null)
throw new Exception("id was bad");
if (entity.tblContentData == null)
entity.tblContentData = new tblContentData();
//proceed with updating the foreign keyed table