Why does the first linq query work, but the second one does not?
var locations =
from routeLocation in db.Table<RouteLocation>()
join location in db.Table<Location>() on routeLocation.LocationId equals location.Id
where functionalLocation.RouteId == routeId
select new Location() { Id = location.Id, ParentId = location.ParentId,
Name = location.Name
};
var locations =
from routeLocation in db.Table<RouteLocation>()
join location in db.Table<Location>() on routeLocation.LocationId equals location.Id
where functionalLocation.RouteId == routeId
select new { Location = location };
The compiler error for the second query is:
Cannot implicitly convert type
'System.Collections.Generic.List<<anonymous type: Location Location>>'
to 'System.Collections.Generic.List<Location>
I tried declaring the var as a List of Location instead, but still get the same error. Is it possible for me to use the syntax in the second example, instead of having to specify each property as in the first example?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…