Prezado(as),
Estou com erro no VS2017 para criar as controllers usando a classe IdentityModels. Compilei o projeto e não apresentou erros, mas quando vou criar qualquer controller da o seguinte erro:
"Erro ao executar o gerador de código selecionado:
Não é possível recuparar metadados para o projeto 'ProjetoBarber.Models.Agenda'. One or more validation erros were detected during model generation:
ProjetoBarber.Models.ApplicationIdentity::EntityType 'Applicationindetity' has no key defined. Define the key for this EntityType.
ApplicationIdentities: EntitySet 'ApplicationIdentities' is based on type 'ApplicationIdentity' that has no keys defines."
Lembrando que esse erro está acontecendo com qualquer classe, mesmo sem ter o relacionamento com usuários.
Segue o código criado pelo Identy na classe IdentityModels:
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace ProjetoBarber.Models
{
// É possível adicionar dados do perfil do usuário adicionando mais propriedades na sua classe ApplicationUser, visite https://go.microsoft.com/fwlink/?LinkID=317594 para obter mais informações.
public class ApplicationUser : IdentityUser
{
public string PrimeiroNome { get; set; }
public string Sobrenome { get; set; }
public string Telefone { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Observe que o authenticationType deve corresponder àquele definido em CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Adicionar declarações de usuário personalizado aqui
userIdentity.AddClaim(new Claim("Nome", this.PrimeiroNome));
userIdentity.AddClaim(new Claim("Id", this.Id));
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
//public ApplicationDbContext() : base("ConnDB", throwIfV1Schema: false) { }
public DbSet<Agenda> Agendas { get; set; }
public DbSet<Foto> Fotos { get; set; }
public DbSet<Servico> Servicos { get; set; }
public DbSet<Horario> Horarios { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
Segue aqui o código da classe Agenda para referência:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ProjetoBarber.Models
{
public class Agenda
{
[Key]
public int ID { get; set; }
[Display(Name = "Serviço")]
public int IDServico { get; set; }
[Display(Name = "Cliente")]
public int IDUsuario { get; set; }
[Display(Name = "Data/Horário")]
public int IDHorario { get; set; }
[Display(Name = "Autorização")]
public bool AutorizacaoAgenda { get; set; }
//chaves extrangeiras
public List<Horario> Horarios { get; set; }
public List<Servico> Servicos { get; set; }
public List<ApplicationIdentity> Usuarios { get; set; }
}
}
Estou aprendendo e espero que alguém possa me ajudar.
Obrigado.
Abs.