简体   繁体   English

ASP.NET 核心 Web API - 如何在实体框架结果中获取所有员工用户详细信息和角色

[英]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.

相关问题 ASP.NET 核心 Web API 使用实体框架核心 - ASP.NET Core Web API using Entity Framework Core 如何使用实体框架通过 ASP.NET Core Web API 处理通用查询? - How can I process a generic query through ASP.NET Core Web API using Entity Framework? ASP.NET Core 2身份/实体框架-如何在User类中获取自定义属性? - ASP.NET Core 2 Identity/Entity Framework - How to get the custom properties within the User class? ASP.NET 核心 Web API - 使用实体框架在 .NET 核心 6 中播种数据 - ASP.NET Core Web API - seeding data in .NET Core 6 using Entity Framework 如何在 Asp.Net 中使用 Web Api 在 Entity Framework 6 中实现事务? - How to implement transaction in Entity Framework 6 with Web Api in Asp.Net? 如何使用 jwt 和身份框架注销 asp.net 核心 web API 中的用户 - How to logout user in asp.net core web API with jwt and identity framework ASP.NET Core Web API 和角色授权 - ASP.NET Core Web API and roles authorization asp.net 核心 Web API:使用 Roles 和 RequiredScope 并发 - asp.net core Web API: use Roles and RequiredScope concurrent ASP.NET Core Web API 和 Entity Framework 同时检查实体是否存在于数据库中 - ASP.NET Core Web API and Entity Framework simultaneously check if entity exists in database ASP.NET Core Web API &amp; Entity Framework Core; 为什么我收到这个错误? - ASP.NET Core Web API & Entity Framework Core; why am I getting this error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM