@AS
Did you really call First() during testing?
The problem seems to be caused by not calling this method.
Linq WhereListIterator issue
My code is
AreaTimePlan[LocationPlanLoop - 1].AllocatedLocation = (Location)(from newLoc in Global.Locations where newLoc.ToLocations.First()== Flight.Origin && newLoc.Type.Title == AreaTimePlan[LocationPlanLoop - 1].LocationType.Title select newLoc).First();
Global.Locations is a list of Location objects
Flight.Origin is a single Location object
NewLoc.ToLocations is a list of Location objects
I get a runtime error - Unable to cast object of type 'WhereListIterator`1[Airport_Server.Location]' to type 'Airport_Server.Location'.'
My intention is that AreaTimePlan[LocationPlanLoop - 1].AllocatedLocation contains a Location which has a ToLocation equal to Origin.
Firstly I'm not sure if I need to use a cast or re-write my Linq query? Secondly whichever I need to use I would appreciate help on the correct implementation.
Thanks
Developer technologies | C#
-
Timon Yang-MSFT 9,606 Reputation points
2021-01-13T08:26:27.87+00:00