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
Relationships of AppUser causes "The property 'AppUser.ExtraProperties' could not be mapped." #1414
Comments
see: #927 |
As you can see, I added "b.ConfigureExtraProperties()", but it only works without entities relationships. The following code is available:
To solve this problem, I even tried this:
to replace:
or keep both. Maybe Thank you for your help, but I still don't know how to solve it. |
@hikalkan @maliming I've found a way.
to replace:
It solves the problem. And by the way, setting properties in |
Hi @gdlcf88, We will document various ways of extending entities of a reusable module (like Identity here). But I will provide a solution for your case: Do not add navigation properties to other aggregate roots. For your case, Don't add navigation property to User from Organization. This is an important rule for DDD. ABP doesn't force every DDD rule, however, for this reusable modules, this is the way to create dbcontext per model and bring all modules together as a single db migration. So, change your entities like: AppUser: public class AppUser : FullAuditedAggregateRoot<Guid>, IUser
{
public virtual Guid? OrganizationId { get; protected set; }
} Organization: public class Organization : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
[Required]
public virtual Guid? TenantId { get; protected set; }
} Change your ConfigureCustomUserProperties method like this: public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b)
where TUser: class, IUser
{
b.Property<Guid?>(nameof(AppUser.OrganizationId));
b.HasOne<Organization>().WithMany().HasForeignKey(nameof(AppUser.OrganizationId));
} Add this to ConfigurePhoneBook method: builder.Entity<Organization>(b =>
{
b.ToTable(PhoneBookConsts.DbTablePrefix + "Organizations", PhoneBookConsts.DbSchema);
b.ConfigureFullAuditedAggregateRoot();
}); The resulting migration for me is: protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "OrganizationId",
table: "AbpUsers",
nullable: true);
migrationBuilder.CreateTable(
name: "AppOrganizations",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
ExtraProperties = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
CreatorId = table.Column<Guid>(nullable: true),
LastModificationTime = table.Column<DateTime>(nullable: true),
LastModifierId = table.Column<Guid>(nullable: true),
IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(nullable: true),
DeletionTime = table.Column<DateTime>(nullable: true),
TenantId = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppOrganizations", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AbpUsers_OrganizationId",
table: "AbpUsers",
column: "OrganizationId");
migrationBuilder.AddForeignKey(
name: "FK_AbpUsers_AppOrganizations_OrganizationId",
table: "AbpUsers",
column: "OrganizationId",
principalTable: "AppOrganizations",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
} Creating a separated dbcontext per module, but managing a single unified db migration path is a big problem with EF core and we provide a model to solve it. |
@hikalkan Learned a lot from you. |
@abllyboy |
@hikalkan What is this witchcraft. can you explain this. besides the above code helped me to do this
Are there any serious issues if I keep |
So is it I am on my first few days of ABP Framework and it took a while to wrap my head around the |
Why is it so hard to understand that we (the consumers of ABP) need to own the domain for the application user. And we need to extend that domain using simple Entities. Common use cases:
These extra entities easily fit into the whole idea of a Domain. These headings may not, in all circumstances deserve their own domain. FFS guys! Quit being soup (or, rather, DDD) nazis! How about this, why don't you just stop trying to ram navigation properties into your Extra Properties collection? |
AppUser:
Organization:
Run "Add-Migration" and it responses:
The property 'AppUser.ExtraProperties' could not be mapped, because it is of type 'Dictionary<string, object>' 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 tried:
And it works, but built a Table names "AppUser". (Not "AbpUsers")
DbContext:
MigrationsDbContext.cs:
Don't know what to do :(
The text was updated successfully, but these errors were encountered: