Установка первичного ключа IdentityUserRole. Для типа сущности IdentityUserRole<Guid> требуется определить первичный клю ⇐ C#
Установка первичного ключа IdentityUserRole. Для типа сущности IdentityUserRole<Guid> требуется определить первичный клю
I'm trying to extend the identity entities however am experiencing an issue with my entity which extends from IdentityUserRole, giving a runtime error of:
Unable to create a 'DbContext' of type ''. The exception 'The entity type 'IdentityUserRole' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I've extended all identity tables:
public class AppRole : IdentityRole { } public class AppRoleClaim : IdentityRoleClaim { } public class AppUser : IdentityUser { } public class AppUserClaim : IdentityUserClaim { } public class AppUserLogin : IdentityUserLogin { } public class AppUserRole : IdentityUserRole { } public class AppUserToken : IdentityUserToken { } And my context is defined as:
public class AppDBContext(DbContextOptions options) : AppDBContext(options) { } The primary key for the AppUserRole table entity should consist of the two foreign keys pointing to the related tables, UserId and RoleId. This is the default primary key, however does not appear to be working when extending the IdentityUserRole table.
I've tried the suggestions in the docs:
Annotations dont work
I have tried to specify this primary key using attributes, however this makes no difference (It seems like none of the common attributes are acknowledged on the identity tables, TableAttribute, PrimaryKeyAttribute etc).
[PrimaryKey(nameof(UserId), nameof(RoleId))] public class AppUserRole : IdentityUserRole { } Fluent API doesnt work
I've also tried setting this via the fluent API in the OnModelCreating method, however again this doesnt seem to make any difference and I get the same error:
protected override void OnModelCreating(ModelBuilder builder) { this.OnModelCreating(builder); builder.Entity().HasKey(e => new { e.UserId, e.RoleId }); } How can I specify the primary key for this table?
Interestingly, if I define my context with the default IdentityUserRole type, it works absolutely fine:
public class AppDBContext(DbContextOptions options, IConfiguration config) : AppDBContext(options) { } For some reason, EF just isnt able to work out the primary key when extending the IdentityUserRole entity, and it seems to be ignoring my attempts to specify the primary key.
Any help resolving this would be appreciated.
Источник: https://stackoverflow.com/questions/780 ... erroleguid
I'm trying to extend the identity entities however am experiencing an issue with my entity which extends from IdentityUserRole, giving a runtime error of:
Unable to create a 'DbContext' of type ''. The exception 'The entity type 'IdentityUserRole' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I've extended all identity tables:
public class AppRole : IdentityRole { } public class AppRoleClaim : IdentityRoleClaim { } public class AppUser : IdentityUser { } public class AppUserClaim : IdentityUserClaim { } public class AppUserLogin : IdentityUserLogin { } public class AppUserRole : IdentityUserRole { } public class AppUserToken : IdentityUserToken { } And my context is defined as:
public class AppDBContext(DbContextOptions options) : AppDBContext(options) { } The primary key for the AppUserRole table entity should consist of the two foreign keys pointing to the related tables, UserId and RoleId. This is the default primary key, however does not appear to be working when extending the IdentityUserRole table.
I've tried the suggestions in the docs:
Annotations dont work
I have tried to specify this primary key using attributes, however this makes no difference (It seems like none of the common attributes are acknowledged on the identity tables, TableAttribute, PrimaryKeyAttribute etc).
[PrimaryKey(nameof(UserId), nameof(RoleId))] public class AppUserRole : IdentityUserRole { } Fluent API doesnt work
I've also tried setting this via the fluent API in the OnModelCreating method, however again this doesnt seem to make any difference and I get the same error:
protected override void OnModelCreating(ModelBuilder builder) { this.OnModelCreating(builder); builder.Entity().HasKey(e => new { e.UserId, e.RoleId }); } How can I specify the primary key for this table?
Interestingly, if I define my context with the default IdentityUserRole type, it works absolutely fine:
public class AppDBContext(DbContextOptions options, IConfiguration config) : AppDBContext(options) { } For some reason, EF just isnt able to work out the primary key when extending the IdentityUserRole entity, and it seems to be ignoring my attempts to specify the primary key.
Any help resolving this would be appreciated.
Источник: https://stackoverflow.com/questions/780 ... erroleguid
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Тип сущности «IdentityUserLogin
» требует определения первичного ключа [дубликат]
Anonymous » » в форуме C# - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Однонаправленное сопоставление OneToOne в сущности со стороной первичного ключа.
Anonymous » » в форуме JAVA - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Однонаправленное сопоставление OneToOne в сущности со стороной первичного ключа.
Anonymous » » в форуме JAVA - 0 Ответы
- 23 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Однонаправленное сопоставление OneToOne в сущности со стороной первичного ключа.
Anonymous » » в форуме JAVA - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-