I have injected IdentityUser to User table. EF created N:N UserStudent table.
SELECT TOP
[Email]
FROM [model].[dbo].[AspNetUsers] A, [model].[dbo].[AspNetUserRoles] B
where
A.Id = B.UserId and B.RoleId = 'parent'
and
A.Id = (select UserId from [model].[dbo].[UserStudent] where StudentId = 'X')
Jignesh KumarPosted May 2, 2023, 3:44 AM
Hello Dave Bell,
Please try this one,
Dave BellPosted May 2, 2023, 4:24 PM
Thanks Jignesh. This works perfectly. Could you please help on how to tweat below for in (as I might get more than 1 records - teachers and parent)
var result = ( from user in context.AspNetUsers join userRole in context.AspNetUserRoles on user.Id equals userRole.UserId where userRole.RoleId == "parent" &&
user.Id ==(in?) (from userStudent in context.UserStudent where userStudent.StudentId == "X" select userStudent.UserId).FirstOrDefault() select user.Email )
.FirstOrDefault();Rajkiran SwainPosted May 2, 2023, 7:38 AM
var result = (from u in context.AspNetUsers
join ur in context.AspNetUserRoles on u.Id equals ur.UserId
join us in context.UserStudent on u.Id equals us.UserId
where ur.RoleId == "parent" && us.StudentId == "X"
select u.Email).FirstOrDefault();
Dave BellPosted May 2, 2023, 1:08 AM
But UserRoles is not in my dbContext. It was created by injecting IdentityUser. I think they are accessible use UserManager
Jay PankhaniyaPosted May 1, 2023, 1:17 PM