[英]ASP.NET Core Web API - How get all employees user details and roles in Entity Framework result
I am implementing ASP.NET Identity Db Context, in ASP.NET Core-6 Web API Entity Framework.我正在 ASP.NET Identity Db Context,在 ASP.NET Core-6 Web API Entity Framework 中。 I have these models:
我有这些模型:
public class Employee
{
public Guid Id { get; set; }
public string UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MobileNumber { get; set; }
public Guid DepartmentId { get; set; }
public virtual ApplicationUser User { get; set; }
}
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MobileNumber { get; set; }
[DefaultValue(false)]
public bool? IsAdmin { get; set; }
}
public class ApplicationRole : IdentityRole
{
public bool? IsActive { get; set; }
}
Entity Configuration:实体配置:
public class ApplicationRoleConfigurations : IEntityTypeConfiguration<ApplicationRole>
{
public void Configure(EntityTypeBuilder<ApplicationRole> builder)
{
builder.HasIndex(r => r.Name).IsUnique();
builder.Property(r => r.IsActive).HasDefaultValue(true);
}
}
public class ApplicationUserConfigurations : IEntityTypeConfiguration<ApplicationUser>
{
public void Configure(EntityTypeBuilder<ApplicationUser> builder)
{
builder.HasIndex(u => u.Email).IsUnique();
builder.HasIndex(u => u.UserName).IsUnique();
builder.Ignore(u => u.AccessFailedCount);
builder.Ignore(u => u.LockoutEnabled);
builder.Ignore(u => u.TwoFactorEnabled);
builder.Ignore(u => u.ConcurrencyStamp);
builder.Ignore(u => u.LockoutEnd);
builder.Ignore(u => u.EmailConfirmed);
builder.Ignore(u => u.TwoFactorEnabled);
builder.Ignore(u => u.AccessFailedCount);
builder.Ignore(u => u.PhoneNumberConfirmed);
builder.Property(u => u.IsActive).HasDefaultValue(true);
builder.Property(u => u.IsAdmin).HasDefaultValue(false);
}
}
Then, I have this query to get all the employees with their user details and roles:然后,我有这个查询来获取所有员工的用户详细信息和角色:
public IQueryable<Employee> GetAllEmployees(PagingFilter filter)
{
var employees = _dbContext.Employees
.Include(x => x.User);
return employee;
}
But it is not giving me the desired result.但这并没有给我想要的结果。
How do I get all the employees with their user details and roles?我如何获得所有员工的用户详细信息和角色?
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.