Have you tried the Include method?
http://weblogs.asp.net/zeeshanhirani/archive/2008/07/03/eager-loading-self-referencing-table-in-linq-to-sql.aspx
I haven't played with this much on L2S, but in the EF there is a similar
limitation in that it can't just perform an arbitrarily deep recursive query
for you or even let you specify a number of levels deep that you'd like it
to go.
That said, this is a bit easier in EF than the kind of code you wrote above
for L2S. With the EF you can just specify however many levels you would
like in your Include string.
So, if you had an example like yours above with a Category entity which has
a Categories set containing nested categories, and if you wanted to go up to
5 levels deep, then you could just do something like this:
foreach (var category in
ctx.Categories.Include("Categories.Categories.Categories.Categories"))
{
// do something
}
This would load the top level categories as well as up to 4 more levels
underneath them. Of course you do have to keep in mind that this would
produce a single, potentially very large query to return all the results.
So I would recommend perf testing it to decide if you want this approach or
if you want to manually write multiple smaller queries...
- Danny
On Fri, Feb 6, 2009 at 5:46 PM, Muhammad Niaz <[email protected]
> wrote:
> Parker,
>
> Basically I am using a table with self join, like Employee table, which
> also have a column of BossId( in my case parented).
>
> Although it's very simple using SQL or LINQ, but I am bound due to *.edmx
> file (image attached) Entity Framework etc. Under Navigation properties
> ProgressNoteType1 is parent Object.
>
>
>
>
>
> Understand.?
>
>
>
>
>
>
>
> Thanks in advance.
>
>
>
> Rregards,
>
> -N
>
>
>
>
>
>
>
>
>
> *From:* Jonathan Parker [mailto:[email protected]]
> *Sent:* Friday, February 06, 2009 11:14 AM
> *To:* [email protected]
> *Subject:* Re: Selft Join
>
>
>
> Please elaborate.
>
> On Fri, Feb 6, 2009 at 4:26 PM, Muhammad Niaz <
> [email protected]> wrote:
>
> PFA,
>
>
>
> Hi all,
>
> Can anybody help me in this regards, Here is the scenario,
>
> I have a table, with Id, Description, ParentId, (selft join). i want to get
> the records using Entity Framework and LINQ query.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Thanks in Advance.
>
> Niaz
> ------------------------------
>
> Support procedure: https://www.codify.com/lists/support
> List address: [email protected]
> Subscribe: [email protected]
> Unsubscribe: [email protected]
> List FAQ: http://www.codify.com/lists/ozsilverlight
> Other lists you might want to join: http://www.codify.com/lists
>
>
> ------------------------------
>
> Support procedure: https://www.codify.com/lists/support
> List address: [email protected]
> Subscribe: [email protected]
> Unsubscribe: [email protected]
> List FAQ: http://www.codify.com/lists/ozsilverlight
> Other lists you might want to join: http://www.codify.com/lists
> ------------------------------
> Support procedure: https://www.codify.com/lists/support
> List address: [email protected]
> Subscribe: [email protected]
> Unsubscribe: [email protected]
> List FAQ: http://www.codify.com/lists/ozsilverlight
> Other lists you might want to join: http://www.codify.com/lists
>
--------------------------------------------------------------------------------
Support procedure: https://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozsilverlight
Other lists you might want to join: http://www.codify.com/lists