New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Can't use AbpUser as navigation property] The property 'AppUser.ExtraProperties' could not be mapped #1517
Comments
try |
The SchoolUsers is inherit from Entity, there is not any b.ConfigureExtraProperties(); for object 'b'. I've tried if i delete |
Dont you have this code in your
|
This is my code:
|
This is a common scenario. While we don't suggest to have navigation properties to other aggregate roots in DDD, it is a common habit among EF Core developers :) |
@yekalkan can you create a new application from the startup template, create the same entities and reproduce the problem. |
I wrote a question about this issue on stack overflow, any help is welcome, thanks! |
Sorry I don't understand why this issue is closed, I think it has not been resolved. @yekalkan Whenever an entity has relationship with |
I agree with you, and this is a temporary solution I found, I hope it can help you in current situation. |
is that meaning never ever use navigation properties in DDD in all conditions? |
I was not using
|
@github-ingenium Thanks for answer, mine came with this error: so I have to used the below:
|
This doesn't work for me because at the next Migration, a new table of AppUser is created. Don't think this should be closed, there still no way to use a Navigation property of AppUser in another entity, without it, EF won't create the FK |
@CAIOHOBORGHI This is the solution I'm using which is working: YourProject.Domain/SomeEntities/SomeEntity.cs public class SomeEntity: AuditedAggregateRoot<Guid>
{
// OTHER PROPERTIES
public Guid UserId { get; set; }
} YourProject.EntityFrameworkCore/EntityFrameworkCore/YourProjectDbContextModelCreatingExtensions.cs builder.Entity<SomeEntity>(b =>
{
b.ToTable("SomeEntity", YourProjectConsts.DbSchema);
b.ConfigureByConvention(); //auto configure for the base class props
b.HasOne<IdentityUser>().WithMany().HasForeignKey(x => x.UserId);
}); YourProject.EntityFrameworkCore/EntityFrameworkCore/YourProjectDbContext.cs [ConnectionStringName("Default")]
public class YourProjectDbContext : AbpDbContext<YourProjectDbContext>
{
public DbSet<AppUser> Users { get; set; }
public DbSet<SomeEntity> SomeEntities { get; set; }
/* Add DbSet properties for your Aggregate Roots / Entities here.
* Also map them inside YourProjectDbContextModelCreatingExtensions.ConfigureYourProject
*/
public YourProjectDbContext(DbContextOptions<YourProjectDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
/* Configure the shared tables (with included modules) here */
builder.Entity<AppUser>(b =>
{
b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
b.ConfigureByConvention();
b.ConfigureAbpUser();
b.ConfigureExtraProperties();
/* Configure mappings for your additional properties
* Also see the YourProjectEfCoreEntityExtensionMappings class
*/
});
// BUG: Below is a hack to overcome IdentityUser issues
builder.Entity<IdentityUser>().Ignore(x => x.ExtraProperties);
builder.Entity<IdentityUserLogin>().HasKey(x => new { x.UserId, x.LoginProvider });
builder.Entity<IdentityUserRole>().HasKey(x => new { x.UserId, x.RoleId });
builder.Entity<IdentityUserToken>().HasKey(x => new { x.UserId, x.LoginProvider });
builder.Entity<IdentityUserOrganizationUnit>().HasKey(x => new { x.UserId, x.OrganizationUnitId });
/* Configure your own tables/entities inside the ConfigureYourProject method */
builder.ConfigureYourProject();
}
} YourProject.Domain/Users/AppUser.cs [NotMapped]
public override ExtraPropertyDictionary ExtraProperties { get; protected set; } |
Thanks @Znow , with this the FK is created. Still can't use the navigation property but it's better than no FK at all. |
I haven't tested this yet but I have used a solution based on both @Znow and @yekalkan answers
check @yekalkan answer to get the full picture |
I have the same issue here while my AppUser still my aggregate root, I don't even put AppUser as Navigation property inside my entity. builder.Entity<UserSession>(u =>
{
u.ToTable(
ProtocloudConsts.DbTablePrefix + "UserSession",
ProtocloudConsts.DbSchema);
u.HasOne<AppUser>().WithOne().HasForeignKey<AppUser>(x => x.Id);
u.ConfigureByConvention();
u.Property(x => x.AutodeskUserID).IsRequired();
u.Property(x => x.UserName).IsRequired();
u.Property(x => x.MacID).IsRequired();
}); Do we have an official solution for this? Or I have to do a workaround? |
I have the same issue without any solution yet. |
I already do this and navigation property display: |
I don’t use navigation properties, just want to set a foreign key in database. I have the same issue, is there a solution? |
Is there any official solution for the issue yet? |
hello try this after entity configuration
|
I'm working with 0.18.1.I get the error message when add-migration.
The relation of entities like this:
The Entity "SchoolUsers" inherits from Entity like this:
Config:
when add-migration, I've received a error:
if replaced
with
b.Ignore(t => t.User);
add-migration succeed, but when I execute
Repository.WithDetails()
in SchoolAppService, I received another error:This only occured when Relation with AbpUser 。
I've tried #1414 ,It's not working.
@hikalkan , @maliming ,can you help me?
The text was updated successfully, but these errors were encountered: