?
Solved

Linq query help - table that references itself

Posted on 2014-10-06
1
Medium Priority
?
194 Views
Last Modified: 2016-02-15
Hello,

I need to figure how the write the following using linq to entities.  I have a table that references itself, and the syntax is over my head!

Here is the SQL of exactly what I need to run
select pc.*
from projects p
	join projectReferences pr on p.projectGuid=pr.projectGuid
	join projectContent pc on pr.referenceProjectID=pc.projectID
where p.projectID = 1234

Open in new window


The table projectReferences here is what is confusing me, it's not part of my EF model, since there is simply a navigation property.

Any Ideas?
0
Comment
Question by:raterus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 33

Accepted Solution

by:
raterus earned 0 total points
ID: 40365906
Figured this one out using the following linq.  This is using a navigate propoperty "IsReferencedBy" that I created.

(from p in DB.projects
         from pc in DB.projectContents
         where pc.project.isReferencedBy.Any(r => r.projectID == p.projectID
                        && p.projectID == 1234)

Open in new window

0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 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