我正在将 Entity Framework 4.0 与 MySQL 结合使用。
这是我的代码:
using (Entities myEntities = new Entities(dataAccess.GetConnectionString()))
{
student sObj = new student();
sObj.id = stud.id;
sObj.rollNo = stud.rno;
sObj.key = (Int64)stud.key;
myEntities.student.AddObject(sObj);
myEntities.SaveChanges();
long maxId = (from f in myEntities.student select f.id).Max();
logger.Info("maxId: " + maxId);
}
我每次都会得到新的 maxId
,不会出现任何错误。但是当我看到数据库时,没有添加任何行。而这种情况只发生在这张 table 上。对于所有其他表都工作正常。
最佳答案
尝试将其标记为已修改
EntityState.Modified
关于c# - Entity Framework 插入未反射(reflect)在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20004971/