C# EF6对象的关系映射

C# EF6对象的关系映射,c#,linq,entity-framework,C#,Linq,Entity Framework,问题(或低智商) 我正在尝试为报表数据库的复杂对象创建EF6映射配置。重新思考物体的结构可能是更明智的做法。但关键因素是,我最初是从生成的XSD方案创建的,我希望保持这两个方案的一致性 这是对象的定义:(非常简单!) 报表是“基类” 课堂报告 { public HeaderObj HeaderObj{get;set;} 公共DataObj DataObj{get;set;} } 班长 { 公共日期时间日期{get;set;} 公共字符串fundID{get;set;} } 类DataObj {

问题(或低智商)

我正在尝试为报表数据库的复杂对象创建EF6映射配置。重新思考物体的结构可能是更明智的做法。但关键因素是,我最初是从生成的XSD方案创建的,我希望保持这两个方案的一致性

这是对象的定义:(非常简单!)

报表是“基类”

课堂报告
{
public HeaderObj HeaderObj{get;set;}
公共DataObj DataObj{get;set;}
}
班长
{
公共日期时间日期{get;set;}
公共字符串fundID{get;set;}
}
类DataObj
{
公共ICollection投资{get;set;}
}
类别投资
{
//…这里有很多成员对象,比如数量和其他东西..你得到了训练。
}
这是我对映射配置的实验:

public class ReportMapping: EntityTypeConfiguration<Report>
{
    public ReportMapping()
        {
//has a composite key: date and fundid, in the object HeaderObj, probably be better off directly under Report class but as im saying, I'm trying to have consistency between the c# classes and the orginal XSD schema.

HasKey(a => new {a.headerobj.date, a.headerobj.fundID});

HasRequired(a => a.HeaderObj);

HasRequired(a => a.dataObj).WithMany(s => s.investments); <-- "computer say no here" although this does make sense to me 

        }
}
公共类ReportMapping:EntityTypeConfiguration { 公共报表映射() { //在对象HeaderObj中有一个复合键:date和fundid,直接在Report类下可能更好,但正如我所说的,我试图在c#类和原始XSD模式之间保持一致。 HasKey(a=>new{a.headerobj.date,a.headerobj.fundID}); haserequired(a=>a.HeaderObj);
HasRequired(a=>a.dataObj)。有许多(s=>s.investments);您正在尝试将日期映射到许多投资。您可能想尝试dataObj。是的,这是正确的。感谢您的通知!:)
public class ReportMapping: EntityTypeConfiguration<Report>
{
    public ReportMapping()
        {
//has a composite key: date and fundid, in the object HeaderObj, probably be better off directly under Report class but as im saying, I'm trying to have consistency between the c# classes and the orginal XSD schema.

HasKey(a => new {a.headerobj.date, a.headerobj.fundID});

HasRequired(a => a.HeaderObj);

HasRequired(a => a.dataObj).WithMany(s => s.investments); <-- "computer say no here" although this does make sense to me 

        }
}
Cannot implicitly convert type 'System.Collections.Generic.ICollection<Investment>' to 'System.Collections.Generic.ICollection<Report>'. An explicit conversion exists (are you missing a cast?)