1
resposta

System.InvalidOperationException: 'The entity type UsuarioAplicacao is not part of the model for the current context.'

após remover o breakpoint, recebo o código de erro quando tento registrar o usuário: System.InvalidOperationException: 'The entity type UsuarioAplicacao is not part of the model for the current context.' Segue código:

using ByteBank.Forum.ViewModels; using ByteBank.forun.Models; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc;

namespace ByteBank.forun.Controllers { public class ContaController : Controller { public ActionResult Registrar() { return View(); }

    [HttpPost]
    public ActionResult Registrar(ContaRegistrarViewModel modelo)
    {
        if (ModelState.IsValid)
        {
            var dbContext = new IdentityDbContext<UsuarioAplicacao>("DefaultConnection");
            var userStore = new UserStore<UsuarioAplicacao>();
            var userManager = new UserManager<UsuarioAplicacao>(userStore);
            var novoUsuario = new UsuarioAplicacao();

            novoUsuario.Email = modelo.Email;
            novoUsuario.UserName = modelo.UserName;
            novoUsuario.NomeCompleto = modelo.NomeCompleto;
            userManager.Create(novoUsuario, modelo.Senha);

            // Podemos incluir o usuario
            return RedirectToAction("Index", "Home");
        }

        // Alguma coisa de errado aconteceu!
        return View(modelo);
    }
    }
}
Onde pode estar meu erro?

segue código da usuarioAplicacao:
using Microsoft.AspNet.Identity.EntityFramework;

using System; using System.Collections.Generic; using System.Linq; using System.Web;

namespace ByteBank.forun.Models { public class UsuarioAplicacao : IdentityUser { public string NomeCompleto { get; set; } } }

1 resposta

Olá Victor,

Duas perguntas:

  1. Pq existem dois colchetes fechando o código?

  2. Olhando a descrição do erro:

System.InvalidOperationException: 'O tipo de entidade UsuarioAplicacao não faz parte do modelo para o contexto atual.'

A entidade "UsuarioAplicacao" está compatível com o seu modelo?

Falow!

Fabio I.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software