- ABP Framework version: v4.3.0
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): no
- Exception message and stack trace: The property 'AppUser.ExtraProperties' could not be mapped because it is of type 'ExtraPropertyDictionary', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
I started to migrate a soution from 4.21 to 4.3, then I did notice that when I regenerate entities of my solution, it was creating index and FK to my navigation properties. As it is a good improvement I wanted to regenerate all entities.
It works well for all my entites except the one which have Navigation properties "AppUserId".
I got a long error message (see attachment bellow), the most important seems this:
The property 'AppUser.ExtraProperties' could not be mapped because it is of type 'ExtraPropertyDictionary', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
I see this line added on MyProjectDbContextModelCreatingExtensions, into builder.Entity<MyExistingEntity>
b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId);
I see some posts about it: https://github.com/abpframework/abp/issues/927 https://github.com/abpframework/abp/issues/1414 https://github.com/abpframework/abp/issues/1517 https://github.com/abpframework/abp/issues/2746
But YourDbContextModelCreatingExtensions.cs is modified by ABP suite just before trying to "generate" my migration script, so I can not test the suggestions
I did some tests and noticed that the error is coming from this line
NOTE: I put a comment to a similar question (without mentionning that it is realted to the update), as it is open since 2 weeks and still not assigned, I post it here.
https://support.abp.io/QA/Questions/1263/abp-suite---AppUser-as-navigation-property-is-not-working
Thanks for your help.
28 Answer(s)
-
0
seems like duplicate of https://support.abp.io/QA/Questions/1263/abp-suite---AppUser-as-navigation-property-is-not-working
-
0
Yes, I was wondering. However they do not mention if it is when running the app or the generated migration script or when the are "building" the entity (which generate the migration script
Following your links I tried:
https://support.abp.io/QA/Questions/1280/The-property-'OrganizationUnitExtraProperties'-could-not-be-mapped-because I added b.ConfigureExtraProperties(); b.ConfigureByConvention(); //This one was already on the code In the method OnModelCreating, into builder.Entity<AppUser> It does not work. I am not 100% sure if I should add this on AppUer or on myEntity. I can not add ConfigureExtraProperties on myEntity, forst because it does not exists for my entity, plus ConfigureMyApp is regenerated when rebuild my entity, so i can not do changes on it
https://support.abp.io/QA/Questions/1271/Add-relation-between-AbpUser-to-My-Table I added builder.ConfigureIdentityPro(); Into ConfigureMyProject method, I then added it into OnModelCreating as it was not working Not working neither
https://github.com/abpframework/abp/issues/8019 About this, not sure I am concerned as I have error even before my migration file get generated.
I will keep doing some tests through information I get from your links though, but I would appreciate some more help as I am not sure to find out the issue.
Thanks
-
0
we are also checking
-
0
Any update about it?
-
0
Is there anyone following this ticket? I am stuck on my migration since about 10 days now and I still have no clue on how or when I will complete it...
Thank you
-
0
Hi,
In
appUser
case, you need change theYourDbContextModelCreatingExtensions
alfter suite added navigation properties.- Remove
b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId);
inYourDbContextModelCreatingExtensions
. - Open
*MigrationsDbContext
, add the following code in theOnModelCreating
method:
builder.Entity<MyExistingEntity>(b => { b.Ignore(x => x.AppUser); b.HasOne<IdentityUser>().WithMany().HasForeignKey(nameof(MyExistingEntity.AppUserId)).IsRequired(false); }); builder.Entity<IdentityUser>(b => { b.Property<Guid?>(nameof(AppUser.MyExistingEntityId)); b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); });
- Open
*DbContext
, add the following code in theOnModelCreating
method:
builder.Entity<AppUser>(b => { b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser b.ConfigureByConvention(); b.ConfigureAbpUser(); /* Configure mappings for your additional properties * Also see the CustomApplicationModulesEfCoreEntityExtensionMappings class */ b.Property<Guid?>(nameof(AppUser.MyExistingEntityId)); b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); }); /* Configure your own tables/entities inside the ConfigureCustomApplicationModules method */ builder.ConfigureCustomApplicationModules(); builder.Entity<MyExistingEntity>(b => { //SET RELATIONS FOR THE PROJECT DBCONTEXT b.HasOne(x => x.AppUser).WithMany().HasForeignKey(nameof(MyExistingEntity.AppUserId)).IsRequired(false); });
Re-create migration files.
- Remove
-
0
I tried your changes but several parts were wrong on the code, I then changed like this:
1- Remove b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId); in YourDbContextModelCreatingExtensions. → OK
2- Open *MigrationsDbContext, add the following code in the OnModelCreating method:
b.Ignore(x => x.AppUser); //Replace by AppUserId as AppUser does not exists
builder.Entity<IdentityUser>(b => { b.Property<Guid?>(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists });
3- Open *DbContext, add the following code in the OnModelCreating method:
b.Property<Guid?>(nameof(AppUser.OrganizationId)); //Replace by Id as OrganizationId does not exists
b.HasOne<MyExistingEntity>().WithMany().HasForeignKey(nameof(AppUser.MyExistingEntityId)); //Replace by Id as MyExistingEntityId does not exists
builder.ConfigureCustomApplicationModules(); // Commented it as I do not have this method I have this instead, but seems the same: builder.ConfigureMyApp();
I guess all the part builder.Entity<Test> was for test? I did try to add it but I do not know what to put to make it working...
After making this changes I then try to create migration files but I got this error:
The property 'Id' cannot be added to type 'IdentityUser' because the type of the corresponding CLR property or field 'string' does not match the specified type 'Nullable<Guid>'
Please keep me updated, I am available for remote connection, it might be faster to solve this than the way we do actually.
Thanks
-
0
Replace by Id as AppUserId does not exists, Replace by Id as MyExistingEntityId does not exists
You should not do this,
AppUserId
andMyExistingEntityId
are foreign key(base entity relationship).See : https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api,fluent-api-simple-key,simple-key#fully-defined-relationships
Your entity should be:
One to one relationship
public class AppUser : ..... { public Guid MyExistingEntityId {get;set;} public MyExistingEntity MyExistingEntity {get;set;} } public class MyExistingEntity : .... { public Guid AppUserId {get;set;} public AppUser AppUser {get;set;} }
One to many relationship
public class AppUser : ..... { public List<MyExistingEntity> MyExistingEntities {get;set;} } public class MyExistingEntity : .... { public Guid AppUserId {get;set;} public AppUser AppUser {get;set;} }
I am available for remote connection, it might be faster to solve this than the way we do actually
Ok, we can. shiwei.liang@volosoft.com
-
0
Hi,
Try:
public class AppUser : ... { public ExistProfile ExistProfile {get;set} } public class ExistProfile : ... { public Guid AppUserId {get;set;} public AppUser AppUser {get;set;} }
MigrationsDbContext
builder.Entity<ExistProfile>(b => { b.Ignore(x => x.AppUser); b.HasOne<IdentityUser>().WithOne().HasForeignKey<ExistProfile>(x => x.AppUserId); });
DbContext
builder.Entity<ExistProfile>(b => { b.HasOne(x => x.AppUser).WithOne(x => x.ExistProfile).HasForeignKey<ExistProfile>(x => x.AppUserId); });
-
0
With this, I got this error:
The relationship from 'StaffProfile' to 'IdentityUser' with foreign key properties {'AppUserId' : Nullable<Guid>} cannot target the primary key {'Id' : string} because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship.
So I tested by creating another field for the primary key in my ExistProfile entity:
public string AppUserIdString { get; set; }
It then generate a script but it is not what I want:
it create a new column, I want to keep AppUserId as it is in production already, i can not change the type. Plus if I want to change the type, I need to change a lot of code
the script create a new table IdentityUser, we are actually using ABPUser table, we can not use another.
-
2
Issue resolved.
After getting the error, everything is generated (UI, back-end) appart of the migration of the migration file.
To go further, some changes need to be done on our code:
1- *DbContextModelCreatingExtensions.cs file:
From the entity you generated, delete this line:
b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId);
2- On EntityGenerated.cs, add:
public AppUser AppUser { get; set; }
3- On AppUser.cs, add:
public EntityGenerated EntityGenerated { get; set; }
4- On OnModelCreating method of *MigrationDbContext.cs, add:
builder.Entity<EntityGenerated >(b => { b.Ignore(x => x.AppUser); b.HasOne<IdentityUser>().WithOne().HasForeignKey<EntityGenerated >(x => x.AppUserId); });
NOTE: Be very careful to use Volo.Abp.Identity.IdentityUser for IdentityUser, by using Microsoft.AspNetCore.Identity.IdentityUser it will not work
5- On OnModelCreating method of *DbContext.cs, add:
builder.Entity<EntityGenerated>(b => { b.HasOne(x => x.AppUser).WithOne(x => x.EntityGenerated).HasForeignKey<EntityGenerated>(x => x.AppUserId); });
Once everything is done, you can now generate the migration script and update the database.
Thanks again Liangshiwei for your support
-
0
Hi upgraded to version 4.4 and still have to delete this line manually to make my solution working after regenerating my entity.
b.HasOne<AppUser>().WithMany().HasForeignKey(x => x.AppUserId);
Any plan/schedule to fix this issue from ABP Framework?
-
0
Hi,
In 4.4 , we have remove the
DbMigrations
project, it will make add navigation properties be easy.You can refer the document: https://community.abp.io/articles/unifying-dbcontexts-for-ef-core-removing-the-ef-core-migrations-project-nsyhrtna
-
0
-
0
Hi,
You can do it, it It is available now.
-
0
Thanks, I will try it then
-
0
-
0
Use
IdentityUser
replaceAppUser
. -
0
Thanks.
As there is no entity named IdentityUser on the entity list,
and there is no file neither
I am filling values manually.
namespace: Volo.Abp.Identity EntityName: IdentityUser DtoName: IdentityUserDto
I will keep Property name AppUserId for now, so it will not change the field on my tables.
Collection name: Users
In my AppDbContext, I will replace:
public DbSet<AppUser> Users { get; set; } by public DbSet<IdentityUser> Users { get; set; }
I did replace AppUser by IdentityUser on my solution to have the project building without any errors.
But now I have this error when try to generate my entity. I already deleted EntityFramework.DbMigration and updated the references as explained on the document.
-
0
-
0
Hi,
You can remove the abp suite cache and try again.
C:\Users\<username>\.abp\suite
-
0
-
0
-
0
I tried with a new solution and do not have this issue to generate a new entity it works well. For my existing solution, could this DbContext name asked be stored somewhere on the database?
-
0
Can I check it remotely? shiwei.liang@volosoft.com