具有接口作为返回类型的实体框架和建模集合

Wil*_*iam 6 c# entity-framework poco

我正在使用Entity Framework v4.我创建了一个包含一堆标量属性的POCO类和一个返回Interface类型的集合.如何在EF模型中创建此关系?如何显示包含不同项目的集合,但它们都具有通用界面?这将是我想要实现的一个例子.

interface IPatientDocument{}
public class Lab : IPatientDocument{.....}
public class Encounter : IPatientDocument{...}
public class MedicationLog : IPatientDocument{...}

//Incomplete class listing
//Once I have aggregated the different doc types, I can then use Linq to Obj to retrieve the specific doc type I need.  Currently I have about 26 doc types and do not want to create a collection for each one
public class Patient
{
   IList<IPatientDocument> DocumentCollection;
}
Run Code Online (Sandbox Code Playgroud)

Doo*_*obi 0

我不知道这是否完全合法。如果您可以使用基类实现,您可能会执行每个类型继承的表,这是允许的。但是,如果您只是尝试选择任意类型,您就会陷入同向和反向差异,这可能值得研究,因为它是 .NET 4 中的新功能。