0
阿帕尔SO我读到这里In Entity Framework, getting the value of an identity column after inserting,如果你这样做:后插入钥匙不能在EF 4.3
var entity = new Entity_Table { item1 = val1, item2 = val2 };
dbcontext.Entity_Tables.Add(entity);
dbcontext.SaveChanges();
int newPK = entity.ID;
你可以得到你插入的行的身份。但是,entity.ID不会出现在我的场景中。
My sceneario: 1. I build the database with a sql script 2. Then I read it as a edmx file 3. Then I ADO.NET DbContext Generator which creates NameOfMyEntity.Context.tt and NameOfMyEntity.tt
我可以插入,更新和删除成功。但我不能看到entity.ID。我在运行时或编译时没有收到任何错误!@ 请帮忙!
正确,你读ID正好是他们命名了他们的键文章。我强烈建议其他人不要在客户/订单表本身上使用“ID”,而不要使用CustomerId,OrderId等。 – 2012-04-02 18:55:11