0
在需要为1-1关系添加新行的情况下,是否需要指定添加或附加?如果需要,我该怎么做?我是否需要指定添加或附加
//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
你需要添加 'db.Entry(实体).STATE = EntityState.Added;'一个新行,或者Entity Framework会为我处理? – 2013-05-14 18:09:08
@ChristopherStevenson - 对于新项目,您应该使用“添加”。当做CRUD => Create's = Add时,Edit的我使用Entry。 – 2013-05-14 18:10:56