I’m having a hard time to figure out how to join aspnet tables using LINQ .
So here’s my inquiries.
How to Join these aspnet tables or how to get the exact column name or data of these aspnet tables using LINQ/MVC 3. aspnet_Membership, aspnet_Users , aspnet_UsersInRoles and aspnet_Roles .
Once I get the values or their column names I’ll be joining them in my two other tables in different database.
here’s my code in sqlserver which I want to convert into LINQ statement.
SELECT AU.UserId,
AU.UserName,
( MNTP.LastName + ',' + MNTP.FirstName + ' '
+ LEFT(MNTP.MiddleName, 1) + '.' ) Name,
AR.RoleName
FROM aspnetdb..aspnet_Membership AM
INNER JOIN aspnetdb..aspnet_Users AU
ON AM.UserId = AU.UserId
INNER JOIN aspnetdb..aspnet_UsersInRoles AUR
ON AU.UserId = AUR.UserId
INNER JOIN aspnetdb..aspnet_Roles AR
ON AUR.RoleId = AR.RoleId
INNER JOIN User_ManagementDB..MNT_Users MNTU
ON AU.UserId = MNTU.aspnet_UsersID
INNER JOIN User_ManagementDB..MNT_Person MNTP
ON MNTU.PersonID = MNTP.ID
And here’s my code in trying to convert it into LINQ statement:
var _rolesRepo = new RolesRepository();
var _users = LoadAll();// Um_MNT_Users
var _person = entities.People.ToList();// UM_Person
var _role = _rolesRepo.LoadAll();
var _userMem = Membership.GetAllUsers()
.Cast<MembershipUser>()
.Select(m => m).ToList(); // I dont know if this is the right syntax to get the aspnet_membership.
var _query = from user in _users
join personID in _person on user.PersonID equals personID.ID
Please help me guys.
Since I don’t see the question being tagged with
Entity FrameworkI assume you can’t create a stored procedure with that logic and call it whenever you need the results…If all your data is in memory you can use this query: