Solved

How to 'force' a type in LINQ?

Posted on 2010-11-16
2
362 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:davecove
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 400 total points
ID: 34147547
I think this is what you are asking, but I may have the type wrong as I tried to infer it from your question. In the event that I am wrong, change "Client.ClientEntities.Location" below to the type name of the type of objects stored in _locations.
var fullCams = from Camera in _cameras
                join Device in _devices on Camera.DeviceId equals Device.Id
                join Client.ClientEntities.Location Location in _locations on Location.Id equals Device.LocationId
                select new _Device { GUID = Device.Id, DisplayName = Device.DisplayName, Type = "Camera" };

Open in new window

0
 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 100 total points
ID: 34147551
Use a fully qualified class name to differentiate between classes with like names, e.g.

Join MyNamespace.MyClassName Location on Location.Id etc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question