TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
592
1.9k
145.9k
Joining table empty result
Jun 20 2020 5:29 AM
I have the following query but when I run it it gaves me error, no data. I have entry in all tables related to user and Roles. What am I doing wrong?
var
role = await (from a
in
_context.UsersData.Where(a => a.Id == id)
join b
in
_context.AppIdentityRoles on a.Id equals b.UserId
join c
in
_context.UsersRole on b.RoleId equals c.Id
select
new
UserDataRole
{
UserId = a.Id,
UserName = a.UserName,
RoleId = c.Id,
RoleName = c.Name
}).ToListAsync();
Data model
public
class
UserDataClass : IdentityUser
{
public
string UserStatus { get; set; }
public
virtual ICollection<AppIdentityRole> AppUserRoles { get; set; }
}
public
class
UserRoleClass : IdentityRole
{
public
virtual ICollection<AppIdentityRole> AppUserRoles { get; set; }
}
public
class
AppIdentityRole : IdentityUserRole<string>
{
public
virtual UserDataClass User { get; set; }
public
virtual UserRoleClass Role { get; set; }
}
public
class
UserDataRole
{
public
string UserId { get; set; }
public
string UserName { get; set; }
public
string RoleId { get; set; }
public
string RoleName { get; set; }
}
Reply
Answers (
22
)
How do I convert my SQL query to entity framework dbcontext
Can we host .net WebAPI in WAS?