【发布时间】:2017-05-15 21:52:31
【问题描述】:
鉴于以下代码,EF/DbContext 如何知道对 customer 对象所做的更改:
class Program
{
static void Main()
{
using(var shopContext = new ShopContext())
{
var customer = shopContext.Customers.Find(7);
customer.City = "Marion";
customer.State = "Indiana";
shopContext.SaveChanges();
}
}
}
public class ShopContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
public string State { get; set; }
}
谢谢
【问题讨论】:
-
对于新读者,这篇博文可能会有所帮助:blog.oneunicorn.com/2012/03/10/…
标签: c# entity-framework-4 dbcontext change-tracking