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()
}
}
これは可能ですか?