我在版本6.2.0中使用Entity Framework
我对这个框架有一个简单的问题
是否可以插入/添加记录,并在使用SaveChanges
函数??
我会尝试用简单的代码表示:
// prepare and add new record
User u = new User();
Context.Users.Add(u);
Context.Entry(u).State = EntityState.Added;
var y = (from x in Context.Users).FirstOrDefault(); // return null
// i expected that, in here i found new Created User
Context.SaveChanges();
var y = (from x in Context.Ussers).FirstOrDefault(); // return != null
我这样做,因为我要加入一个创建的记录和其他几个表。
答案 0 :(得分:0)
DbSet has a Local
property that represents a local view of the set (including Added
, Unchanged
and Modified
entities). You can see Entity Framework Local Data documentation for more information.