可能重复:
How to determine which fields where changed in a Linq-To-Sql Object
如何确定在linq-to-sql中更新实体对象时更新了哪些属性,如:
public class User
{
public int Id { get; set; }
public string Name {get; set; }
public string LastName { get; set; }
}
public void UpdateUser(User user)
{
using (var entity = new CoolEntity())
{
user.Name = user.Name + "%";
entity.SubmitChanges();
//Now here, I would love to know that "Id" and "LastName" is not changed
//but the "Name" property of the object is updated.
}
}
我知道这听起来有点难,也许我的方法不可能;但这是针对伐木结构的;因为我需要记录更新对象属性的更新细节。
我很想知道是否有任何标志可以让我识别出已更改的属性。