Entity Framework(EF):测试DbContext的Add,Remove相同对象是否执行两次SQL
Entity Framework(EF):测试DbContext的Add,Remove相同对象是否执行两次SQL测试结果:
不会产生两段SQL,相当于没有提交。
C# Code:
public static void Do()
{
using (var context = new UserDbContext())
{
context.Database.Log = Console.Write;
Console.WriteLine("Entity Framework(EF):测试DbContext的Add,Remove相同对象是否执行两次SQL");
EFUser model = new EFUser() { Id = 11, Name = "www.CSframework.com" };
var result = context.Users.Add(model);
context.Users.Remove(model);
int i = context.SaveChanges();
Console.WriteLine("Save Changes Result:" + i.ToString());
}
Console.ReadLine();
}