Нет метода включения для диспетчера пользователей ASP.NET Core 2.1 - PullRequest
0 голосов
/ 23 ноября 2018

AppUser содержит свойство типа «Entity», которое содержит собственные вложенные свойства.Как можно загрузить все свойства пользователя, включая свойства в объекте Entity?В объекте UserManager отсутствует метод Include.

AppUser.cs

using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations.Schema;

namespace MyApp.Models
{
    public class AppUser : IdentityUser
    {

        public AppUser()
        {
            this.Entity = new Entity();
        }

        public string FirstName { get; set; }
        public string LastName { get; set; }
        [ForeignKey("EntityFK")]
        public Entity Entity { get; set; }
    }
}

Entity.cs

namespace MyApp.Models
{
    public class Entity
    {
        public int EntityId { get; set; }
        public string Name { get; set; }
        public AppUser AppUser { get; set; }
    }
}

EntityController.cs

using System.Threading.Tasks;
using MyApp.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace MyApp.Controllers
{
    [Authorize(Roles = "Entity")]
    public class EntityController : Controller
    {
        private UserManager<AppUser> userManager;

        public MyAppController(UserManager<AppUser> _userManager)
        {
            userManager = _userManager;
        }

        [HttpGet]
        public async Task<IActionResult> Index()
        {
            /* How can eager loading be used to get the Entity and its properties? */
            AppUser user = await userManager.GetUserAsync(HttpContext.User);
            return View("~/Views/Entity/Index.cshtml", user);
        }
    } 
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...