Tag: foreign key

使用Entity Framework 4.1 Fluent API在非主键字段上创建关联

我们使用EF 4.1和流畅的API从遗留数据库中获取数据(我们不允许更改)。 我们在创建两个表之间的关系时遇到问题,其中相关列不是主键和外键。 使用下面的类,我们如何配置Report和RunStat之间的一对多关系,以便Report.RunStats将返回ReportCode字段相等的所有RunStat实体? public class Report { [Key] public int ReportKey { get; set; } public string Name { get; set; } public int ReportCode { get; set; } // Can we associate on this field? public virtual ICollection RunStats { get; set; } } public class RunStat { [Key] public int RunStatKey { […]