Link to home
Create AccountLog in
Avatar of davecove
davecoveFlag for United States of America

asked on

How to 'force' a type in LINQ?

Here is a LINQ query that works without the second JOIN clause (3rd line) along with the statements that provide the collections used in the query.

The problem is on the 3rd line:

    join Location in _locations on Location.Id equals Device.LocationId

While LINQ is happy parsing the private type Camera and Device, it has problems with the private type Location... behind the word 'on' it wants to use the Point type Form.Location instead of my private type as a range variable although it correctly uses the private type as a range variable earlier in the line just after 'join'.

Is there some syntax I can use to instruct the parser to use the private type in the second position as well?  No, I can't change the name of Location, it is coming from a dll I don't have the source code for.

(BTW: calling the second position out by its full name 'Client.ClientEntities.Location' doesn't help... the parser still doesn't see it as a range variable )


I am not very good with the non-LINQ style of these queries (i.e. the Collection.Select() style) so if there is not a way to force the parser, could someone do me a huge favor and convert my LINQ query to the Select() syntax please?  I have others of these to do, but one good example will get me all that I need.

Thank you for your time,
Dave





var _cameras = DAL.Cameras.ToList();  // Collection of type Camera
var _devices = DAL.Devices.ToList();  //Collection of type Device
var _locations = DAL.Locations.ToList();  //Collection of type Location
                                
var fullCams = from Camera in _cameras
                join Device in _devices on Camera.DeviceId equals Device.Id
                join Location in _locations on Location.Id equals Device.LocationId
                select new _Device { GUID = Device.Id, DisplayName = Device.DisplayName, Type = "Camera" };

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.