使用Linq to entity从表和相关相关表中获取记录

时间:2016-04-09 16:18:03

标签: c# entity-framework linq linq-to-entities

我使用LINQ to entity来从表中检索记录,并从另一个表中查找相关记录。

这是我的关系表:

enter image description here

这是我的LINQ to实体,用于从Sensors Measure和相关表警报描述中检索记录。

A specified Include path is not valid. The EntityType 'SensorObservationModel.AlertsDescription' does not declare a navigation property with the name 'AlertDescription'.

但是在上面的查询中我收到了这个错误:

{{1}}

我知道为什么会出现上述错误以及如何修复它?

1 个答案:

答案 0 :(得分:2)

这是因为AlertDescription不是AlertsDescription类型的 navigation 属性 - 它只是常规属性,因此您不需要包含它。只是做:

public IEnumerable<SensorsMeasure> GetSensorsMeasureWithAlertDescription()
{
    return SensorObservationEntities.SensorsMeasures.Include(d => d.AlertsDescription).ToList();
}
相关问题