我如何使用CreateObjectSet< tenty >其中TEntity作为参数
本文关键字:TEntity 其中 参数 tenty 何使用 CreateObjectSet | 更新日期: 2023-09-27 18:17:03
我正在寻找一种传递实体和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);
改变为
private void AttachSingleEntity<TEntity>(Entity singleEntity) where TEntity:class
{
ObjectSet<TEntity> objectSet = context.CreateObjectSet<TEntity>();
objectSet.Attach(singleEntity);
}