我在实体框架中设置了以下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的记录。
我在这里错过了一些吗?