[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to 'force' a type in LINQ?

Posted on 2010-11-16
2
Medium Priority
?
369 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 1600 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 400 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

825 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