【发布时间】:2010-08-30 03:32:57
【问题描述】:
我有一个通用的 CRUD 类来对我的实体对象执行添加、删除、选择和创建。
其中之一 - Message 有两个派生类 - order_message 和 report_message。
我的问题是,在我的泛型类中,我需要一个对象集来执行 crud ops,但对象集不接受派生类类型,它只接受基类类型。
这是我收到的错误:
没有为指定的实体类型“CustomerWebPortal_Entities.Order_Message”定义实体集。如果“CustomerWebPortal_Entities.Order_Message”是派生类型,请改用基类型。
我尝试使用 typeof(T).BaseType 来替换 T,结果没有用。
我应该如何纠正这个问题?
这是泛型类的概述:
public abstract class baseCrudDao<T> : ICrudDao<T> where T : class
{
private System.Data.Objects.ObjectContext _context;
private System.Data.Objects.ObjectSet<T> _entity;
public baseCrudDao()
{
_context = new CustomerWebPortalEntities();
_entity = _context.CreateObjectSet<T>(); <-- error at here, only accept base type
}
【问题讨论】:
-
您提出的任一解决方案都取得了成功吗?
-
尚未尝试。希望很快。
标签: c# entity-framework type-conversion