Solved

Linq query help - table that references itself

Posted on 2014-10-06
1
173 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ajax Panel Not Updating When Triggered By Timer 4 42
Exit the loop 4 35
Coding C# in Linux 8 31
Crystal reports vb.net 2 7
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now