Solved

Linq query help - table that references itself

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML to SQL Table using c# 5 46
Tabcontrol Caption? 1 24
Throws error on Decrypting String c# code 3 26
Open a word document 23 15
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

21 Experts available now in Live!

Get 1:1 Help Now