Marius Vasile

Marius Vasile

  • 1.6k
  • 227
  • 1.4k

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?
 
  1. var role = await (from a in _context.UsersData.Where(a => a.Id == id)  
  2.                         join b in _context.AppIdentityRoles on a.Id equals b.UserId  
  3.                         join c in _context.UsersRole on b.RoleId equals c.Id  
  4.                         select new UserDataRole  
  5.                         {  
  6.                             UserId = a.Id,  
  7.                             UserName = a.UserName,  
  8.                             RoleId = c.Id,  
  9.                             RoleName = c.Name  
  10.                         }).ToListAsync();  
Data model
  1. public class UserDataClass : IdentityUser  
  2.     {  
  3.         public string UserStatus { get; set; }  
  4.         public virtual ICollection<AppIdentityRole> AppUserRoles { get; set; }  
  5.     }  
  6.       
  7.     public class UserRoleClass : IdentityRole  
  8.     {  
  9.         public virtual ICollection<AppIdentityRole> AppUserRoles { get; set; }  
  10.     }  
  11.   
  12.     public class AppIdentityRole : IdentityUserRole<string>  
  13.     {  
  14.         public virtual UserDataClass User { get; set; }  
  15.         public virtual UserRoleClass Role { get; set; }  
  16.     }  
  17.   
  18.     public class UserDataRole  
  19.     {  
  20.         public string UserId { get; set; }  
  21.         public string UserName { get; set; }  
  22.         public string RoleId { get; set; }  
  23.         public string RoleName { get; set; }  
  24.     }  

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (22)