It is not possible to implicitly convert the type 'System.Collections.Generic.List <T>' to 'System.Linq.IQueryable <T>'
I am trying to create a query in my domain service (VS 2010 Silverlight Business Application) that returns validation results that return as a specific value, my database is configured as:
Locations a) Inspections b) InspectionItems c) InspectionReadings a) Areas b) Inspections c) InspectionItems d) InspectionReadings
So, as you can see, there are inspection indications for places in places and places. I have a POCO named StatusList:
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; } }
which I use to return the query results:
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; }
unfortunately, it returns an error in the title, and I have no idea why, since the list is clearly an element of the list, and I converted the results
.ToList<LocationStatusList>
The problem is that you called ToList()
. You announced that you are returning an IQueryable<LocationStatusList>
, and List<T>
does not implement IQueryable<T>
.
Options (select one):
- Delete the
ToList
call - Change the return type to
IEnumerable<LocationStatusList>
,IList<LocationStatusList>
or possiblyList<LocationStatusList>
Call
AsQueryable()
afterToList()
:... as before ... .ToList().AsQueryable();
Note that you do not need a type argument in the ToList
call - it is the same as the compiler anyway.