我正在寻找一种将Entity和TEntity作为参数传递的方法,以便我可以将此方法用作通用方法。这样的事情:
private void AttachSingleEntity(Entity singleEntity, TEntity Tentity)
{
ObjectSet<Tentity> objectSet = context.CreateObjectSet<Tentity>();
objectSet.Attach(singleEntity);
}
然后我调用AttachSingleEntity如下:
customer cus = new customer {id = 1};
AttachSingleEntity(cus,customer);
答案 0 :(得分:4)
更改为
private void AttachSingleEntity<TEntity>(Entity singleEntity) where TEntity:class
{
ObjectSet<TEntity> objectSet = context.CreateObjectSet<TEntity>();
objectSet.Attach(singleEntity);
}