我使用LINQ to entity来从表中检索记录,并从另一个表中查找相关记录。
这是我的关系表:
这是我的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}}
我知道为什么会出现上述错误以及如何修复它?
答案 0 :(得分:2)
这是因为AlertDescription不是AlertsDescription类型的 navigation 属性 - 它只是常规属性,因此您不需要包含它。只是做:
public IEnumerable<SensorsMeasure> GetSensorsMeasureWithAlertDescription()
{
return SensorObservationEntities.SensorsMeasures.Include(d => d.AlertsDescription).ToList();
}