Warum verstößt dies gegen die Typeinschränkung?
Ich versuche, ASP.NET Identity 3 so anzupassen, dass Integer-Schlüssel verwendet werden:
public class ApplicationUserLogin : IdentityUserLogin<int> { }
public class ApplicationUserRole : IdentityUserRole<int> { }
public class ApplicationUserClaim : IdentityUserClaim<int> { }
public sealed class ApplicationRole : IdentityRole<int>
{
public ApplicationRole() { }
public ApplicationRole(string name) { Name = name; }
}
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, int>
{
public ApplicationUserStore(ApplicationDbContext context) : base(context) { }
}
public class ApplicationRoleStore : RoleStore<ApplicationRole, ApplicationDbContext, int>
{
public ApplicationRoleStore(ApplicationDbContext context) : base(context) { }
}
public class ApplicationUser : IdentityUser<int>
{
}
public sealed class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>
{
private static bool _created;
public ApplicationDbContext()
{
// Create the database and schema if it doesn't exist
if (!_created) {
Database.AsRelational().Create();
Database.AsRelational().CreateTables();
_created = true;
}
}
}
Dies kompiliert in Ordnung, löst dann aber einen Laufzeitfehler aus:
System.TypeLoadException
GenericArguments [0], 'TeacherPlanner.Models.ApplicationUser', in 'Microsoft.AspNet.Identity.EntityFramework.UserStore`4 [TUser, TRole, TContext, TKey]' verletzt die Einschränkung des Typparameters 'TUser'.
Die Signatur fürUserStore
ist:
public class UserStore<TUser, TRole, TContext, TKey>
where TUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser<TKey>
where TRole : Microsoft.AspNet.Identity.EntityFramework.IdentityRole<TKey>
where TContext : Microsoft.Data.Entity.DbContext
where TKey : System.IEquatable<TKey>
ApplicationUser
ist genau einIdentityUser<int>
. Ist es nicht das, wonach es sucht?