问题(或低智商)
我正在尝试为报表数据库的复杂对象创建EF6映射配置。重新思考对象的结构可能是一个更明智的事情。但关键因素是我正在从生成的XSD方案中创建这个,我想保持这两个东西的一致性。
这是对象的定义:(非常简化!)
报告是“基类”
class Report
{
public HeaderObj headerobj {get;set;}
public DataObj dataObj {get;set;}
}
class HeaderObj
{
public DateTime date {get; set;}
public string fundID {get;set;}
}
class DataObj
{
public ICollection<Investment> investments {get;set;}
}
class Investment
{
//....lot of member objects here like Amount and other things..you get the drill.
}
这是我对映射conf的实验:
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?)
如何在没有编译错误的情况下为对象DataObj定义多个投资的正确映射?