en.CreateObjectSet
另外其实 你的实参是多余的,泛型查询类你可以这么写:
public class EntityProvider: IDisposable where T : EntityObject
{
public void Dispose()
{
if (this.entForQueryOnly != null)
{
this.entForQueryOnly.Dispose();
}
}
// 仅查询用
protected NorthwindEntities entForQueryOnly;
public virtual ListGetList()
{
return this.entForQueryOnly.CreateObjectSet().ToList();
}
public virtual ListGetList(System.Linq.Expressions.Expression > predicate)
{
return this.entForQueryOnly.CreateObjectSet().Where(predicate).ToList();
}
//Add
public virtual T Add(T entity)
{
using (NorthwindEntities ent = new NorthwindEntities())
{
try
{
ent.CreateObjectSet().AddObject(entity);
ent.SaveChanges();
return entity;
}
catch
{
return default(T);
}
}
}
}
如果你不用反射Relection,恐怕是找不到答案的.
思路应该是
Type type= t.GetType();
确定Type以后再利用反射从en中找数据集
没试过,自己试试吧.