1
I have a bug in my application. I am working with Identity
for user authentication however when calling Controller
created is returned me the following error:
Multiple Object sets per type are not supported. The Object sets 'Usuarios' and 'Users' can Both contain instances of type 'Project01.Areasc.Security.Models.Usuario'.
Error of origin:
Error of Origin:
Line 33: Line 34: Line 35: @if (Model.Count() == 0) Row 36: { Line 37:
However it does not have two contexts of the same type, I created 2 for the application and another 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 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 any solution?
In the Migrations creation file there is nothing related to Users, only my other 3 tables, Products, Manufacturers and Categories...
– Desalex
you could post the class where the error is happening, then?
– Ayrton Giffoni
The error occurs in the Index view, posted in the initial topic, the section where the error is given..
– Desalex
But only the line that generates the error doesn’t help much. The interesting thing would be to show the whole context of your call. I would indicate you post your entire view, the controller that calls the view, your typed object on the screen would also be interesting. If the application runs, then the problem lies in some logic or modeling. At first I thought the error was time to try to create/update your bank with the Fluent API.
– Ayrton Giffoni