我想写一个函数,它接收任何Entity
对象并通过自动确定的主键找到当前值并更新它。
你能给我指点什么方向吗?
public void Update(object entity)
{
using (var _db = new MyEntities())
{
var table = _db.Set(entity.GetType());
//Here we should somehow find the entity object which primary key coincides with the one of entity
var entityObj = table.FindObjectByPrimaryKey(entity);
entityObj.CopyDataFrom(entity);
_db.SaveChanges()
}
}
这可能吗?