Geeks With Blogs
Rohan Cragg

I wanted to be able to write a hierarchical query in LINQ but found that it’s not something you can do.

I knew how to write TVFs or User Defined Table Valued Functions and had used them in joins in pure TSQL before but I suspected that it ought to be possible to re-use that SQL within an EF model so I went hunting…

Eventually I was inspired by this

First, I added Function Imports for my TVFs to my (classic Database-First edmx) model:


Update from Database:


Function Imports got added:


I also ensured that the Return Type was one of the Entities already in the model:


I love it! – it's an IQueryable just like any other EntitySet:


So that means I can do some LINQ joins between the function and other EntitySets:


Job Done Smile

Posted on Tuesday, July 9, 2013 5:39 PM | Back to top

Comments on this post: Joining to an arbitrary SQL set in EF5

# re: Joining to an arbitrary SQL set in EF5
Requesting Gravatar...
Nice! Thanks for blogging about this in EF5.
Left by Dave Mateer on Jul 09, 2013 5:47 PM

Your comment:
 (will show your gravatar)

Copyright © rohancragg | Powered by: | Join free