Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用LINQtoSQL和业务对象保存和检索继承的类型_Linq_Linq To Sql_Inheritance_Orm_Single Table Inheritance - Fatal编程技术网

使用LINQtoSQL和业务对象保存和检索继承的类型

使用LINQtoSQL和业务对象保存和检索继承的类型,linq,linq-to-sql,inheritance,orm,single-table-inheritance,Linq,Linq To Sql,Inheritance,Orm,Single Table Inheritance,我有一个抽象的EventBase类和一些继承的事件类型,以及一个事件类。每个事件类型都有自己独特的列 在我的数据层中,我有一个GetEvents方法,它只执行以下操作: from e in db.Events select new Event {...values...}; EventType是与EventTypes表匹配的枚举 我希望GetEvents(EventType)和GetEvent(int-id,EventType)执行类似 from e in GetEvents()

我有一个抽象的EventBase类和一些继承的事件类型,以及一个事件类。每个事件类型都有自己独特的列

在我的数据层中,我有一个GetEvents方法,它只执行以下操作:

from e in db.Events
    select new Event {...values...};
EventType是与EventTypes表匹配的枚举

我希望GetEvents(EventType)和GetEvent(int-id,EventType)执行类似

from e in GetEvents()
    where e.TypeId == (int)type
    select new TypeSpecified {...values for Event + Type-specific fields...};

// Determine what type it is
// Switch statement? Dictionary?
我不确定切换是否是最好的主意,但我也不确定如何正确使用字典将数据检索和对象创建映射到特定类型

我的第二个问题涉及到保存数据——从业务对象到L2S表——基本上与上面的问题相同


我希望这是有意义的:)

Rick Strahl的页面帮助我启动并运行我的业务层。这对你来说也是一个好的开始


我的主要问题是我倾向于过度设计业务层。因此,我们必须保持简单,但不能简单;-)

您已经在使用单表继承了吗?IE是否定义了一个包含所有可能列的表,以及标识每行类型的鉴别器列?如果不知道你是否已经在使用它,很难回答你的问题。