EntityFramework导航属性未按预期工作

时间:2016-10-05 18:05:14

标签: c# .net entity-framework

我在实体框架中设置了以下3个(简化)类

public class Service
{
    [Key]
    public int ServiceId { get; set; }
    public int WorkformId { get; set; }

    [ForeignKey("WorkformId")]
    public virtual Workform Workform { get; set; }
}


public class Workform
{
    [Key]
    public int WorkformId { get; set; }

    [ForeignKey("WorkformId")]
    public virtual ICollection<FieldMap> FieldMaps { get; set; }
 }


public class FieldMap
{
    [Key]
    public int FieldMapId{ get; set; }
    public int WorkformId{ get; set; }
 }

如果我尝试做这样的事情

var service = db.Services.Include("Workform.FieldMaps")
                .FirstOrDefault(p => p.ServiceId == serviceId);

service.Workform.FieldMaps正在拉动整个集合,而不仅仅是具有匹配关系id的记录。

我在这里错过了一些吗?

0 个答案:

没有答案