使用Linq到实体从表和相关的相关表中获取记录 [英] Get records from table and related related table using Linq to entity
本文介绍了使用Linq到实体从表和相关的相关表中获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用LINQ进行实体检索以从表中检索记录,并从另一个表中检索相关记录.
I use LINQ to entity to retrive records from table and there related records from another table.
这是与我有关的表:
这是我的LINQ to实体,用于从Sensor Measure和相关的表警报描述中检索记录.
And here is my LINQ to entity to retrieve records from Sensors Measure and related table alert description.
public IEnumerable<SensorsMeasure> GetSensorsMeasureWithAlertDescription()
{
return SensorObservationEntities.SensorsMeasures.Include(d => d.AlertsDescription.AlertDescription).ToList();
}
但是在上面的查询中,我收到此错误:
But on the query above I get this error:
A specified Include path is not valid. The EntityType 'SensorObservationModel.AlertsDescription' does not declare a navigation property with the name 'AlertDescription'.
有什么主意,为什么我会得到上面的错误以及如何解决?
Any idea why I get the error above and how to fix it?
推荐答案
这是因为AlertDescription不是AlertsDescription类型的 navigation 属性-它只是常规属性,因此您无需包含它.只要做:
That's because AlertDescription is not navigation property of AlertsDescription type - it's just regular property, so you don't need to include it. Just do:
public IEnumerable<SensorsMeasure> GetSensorsMeasureWithAlertDescription()
{
return SensorObservationEntities.SensorsMeasures.Include(d => d.AlertsDescription).ToList();
}
这篇关于使用Linq到实体从表和相关的相关表中获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文