Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF for cross reference tables?

$
0
0

I'm new to EF and Linq and wondering what's the best and simplest way to query 3 relational tables with one being a many-to-many.  

Say I have the following Tables:

  1. Roles (Role_CID, Role)
    2. Users (User_CID, Username)
    3. Xref (Role_CID, User_CID)

and I want to return all of the roles for user 'Joe'.  With t-Sql I could simply:

select Role from Roles r
inner join XRef x on x.Role_CID = r.Role_CID
inner join User u on u.User_CID = x.User_CID
where u.Username = 'Joe'

What's the best way to return the list of Roles?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>