Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert SQL Query To Linq
Message
De
22/06/2010 07:15:39
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Divers
Thread ID:
01470083
Message ID:
01470149
Vues:
33
>>I could use some help converting this to linq:
>>
>>
>>SELECT u.*
>>	FROM aspnet_Users u
>>	JOIN aspnet_UsersInRoles ur ON ur.UserId = u.UserId
>>	WHERE ur.RoleId = @RoleId
>>
>>
>>
>>I have this so far:
>>
>>
>>var user = from u in dc.aspnet_Users
>>            where u.
>>            select u;
>>
>
>How about something like this...
>
>
>var query = from u in dc.aspnet_users where u.aspnet_UsersInRoles.RoleId = RoleId select u;
>
>User usr = query.FirstOrDefault();
>
>
>
>Kurt

Kurt,
I think aspnet_users have unique users (u) where each u can have many Roles (ur) - 1-to-many relation. Of course I can't be sure of that. If I am right, this wouldn't work because u.aspnet_UsersInRoles is an IEnumerable (not a scalar). However you could do it like that if you change the checking:
var query = from ur in dc.aspnet_UsersInRoles
    where ur.RoleId = RoleId 
    select ur.aspnet_User; // assuming in Model navigation from Roles to Users is renamed to be singular

var users = query.Distinct();
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform