xhe*_*igx 7 c# linq-to-entities visual-studio-2010 hierarchical-data silverlight-5.0
我正在尝试在我的域服务(VS 2010 Silverlight业务应用程序)中创建一个查询,该查询返回作为特定值出现的检查读数的结果,我的数据库设置为:
Locations
a) Inspections
b) InspectionItems
c) InspectionReadings
a) Areas
b) Inspections
c) InspectionItems
d) InspectionReadings
Run Code Online (Sandbox Code Playgroud)
因此,正如您所看到的,区域和位置下的位置有检查读数.我有一个名为StatusList的POCO:
public class StatusList
{
[Key]
[Editable(false)]
public Guid ID { get; set; }
public string LocationName { get; set; }
public DateTime LastInspectionDate { get; set; }
public string Status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我用它来返回查询的结果:
public IQueryable<StatusList> GetLocationStatus()
{
var status = (from location in this.ObjectContext.Locations
where location.InspectionReadings.Status == value
orderby a.DateTaken
select new LocationStatusList()
{
ID = a.ID,
LocationName = d.Name,
}).ToList<StatusList>();
return status;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它返回标题中的错误,我不知道为什么列表显然是一个列表项,我已经转换了结果
.ToList<LocationStatusList>
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 22
问题正是因为你打电话了ToList().你已经声明你正在返回IQueryable<LocationStatusList>,并且List<T>没有实现IQueryable<T>.
选项(选择一个):
ToList电话IEnumerable<LocationStatusList>,IList<LocationStatusList>或者可能List<LocationStatusList>通话AsQueryable()后ToList():
... as before ...
.ToList().AsQueryable();
Run Code Online (Sandbox Code Playgroud)请注意,您不需要ToList调用中的type参数- 它与编译器推断的相同.