I have an error in my application. I am working with Identity
for user authentication but calling Controller
created is returned the following error:
Multiple object sets per type are not supported. The object sets 'Users' and 'Users' can both contain instances of type 'Project01.Areas.Seguranca.Models.Usuario'.
Source error:
Source Error:
Line 33: Line 34: Line 35: @if (Model.Count () == 0) Line 36: { Line 37:
But it does not have two contexts of the same type, I have created 2 for the application and the other for the identity
.
namespace Persistencia.Contexts
{
public class EFContext : DbContext
{
public EFContext()
: base("EFContext") {
Database.SetInitializer<EFContext>(
new MigrateDatabaseToLatestVersion<EFContext, Configuration>());
}
protected override void OnModelCreating(
DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
public DbSet<Categoria> Categorias { get; set; }
public DbSet<Fabricante> Fabricantes { get; set; }
public DbSet<Produto> Produtos { get; set; }
}
}
and the other:
namespace Projeto01.DAL
{
public class IdentityDbContextAplicacao :
IdentityDbContext<Usuario>
{
public static object DataBase { get; private set; }
public IdentityDbContextAplicacao() : base("IdentityDb")
{}
static IdentityDbContextAplicacao()
{
Database.SetInitializer<IdentityDbContextAplicacao>
(new IdentityDbInit());
}
public static IdentityDbContextAplicacao Create()
{
return new IdentityDbContextAplicacao();
}
public DbSet<Usuario> Usuarios { get; set; }
}
public class IdentityDbInit: DropCreateDatabaseIfModelChanges
<IdentityDbContextAplicacao>
{ }
}
View where the error occurs:
<tbody>
@if (Model.Count() == 0)
{
<tr>
<td colspan="3" class="text-center">
Sem usuários registrados
</td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Alterar", "Edit", new { id = item.Id })
|
@Html.ActionLink("Detalhes", "Details", new { id = item.Id }) |
@Html.ActionLink("Eliminar", "Delete", new { id = item.Id })
</td>
</tr>
}
}
</tbody>
Can anyone see a solution?