aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 868 forks source link

Many-to-many relationship between IdentityRoleClaim and IdentityRole and message: Only backing fields of types that are assignable from the property type can be used. #1855

Closed ghost closed 6 years ago

ghost commented 6 years ago

More information on the context can be found here:

I get this:

The specified field 'k__BackingField' of type 'Guid' cannot be used for the property 'ApplicationIdentityRoleClaim.Id' of type 'int'. Only backing fields of types that are assignable from the property type can be used.

Here a repo

ajcvickers commented 6 years ago

Note for triage: the issue is triggered by a hiding a property in a mapped base class with another property in the derived class when attempt is made to include them both in the model. Simplified repro:

public class Blog
{
    public int Id { get; set; }
}

public class ABlog : Blog
{
    public new Guid Id { get; set; }
}

public class BloggingContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder
            .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ABlog>(b =>
        {
            b.Property(e => ((Blog) e).Id);
            b.Property(e => e.Id);
        });
    }
}

public class Program
{
    public static void Main()
    {
        using (var context = new BloggingContext())
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
        }
    }
}
ajcvickers commented 6 years ago

Moved to https://github.com/aspnet/EntityFrameworkCore/issues/12565

ghost commented 6 years ago

As I did before :p