Adding a new field to the Abp.io base tables like AbpRoles
As per the Abp.io document https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations , I tried to add a new field 'Title' in AppRole class
[Audited] [System.ComponentModel.DataAnnotations.Schema.Table("AbpRoles")]
public class AppRole : AggregateRoot, IHasConcurrencyStamp, IHasExtraProperties {
......
public virtual string Title { get; set; }
.............
}
In ApiDbContext, i have added the below lines,
builder.Entity<AppRole>(b =>
{
b.ToTable("AbpRoles");
b.ConfigureByConvention();
b.Property(x => x.Title).HasMaxLength(128);
});
Then same has been added to ApiMigrationsDbContext class
builder.Entity(b =>
{
b.ToTable("AbpRoles");
b.ConfigureByConvention();
b.Property(x => x.Title).HasMaxLength(128);
});
I am getting the following error during migration
Cannot use table 'AbpRoles' for entity type 'IdentityRole' since it is being used for entity type 'AppRole' and there is no relationship between their primary keys.
The document talks about the following approach also. But i am not able to find the ObjectExtensionManager.
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityRole, string>(
"Title",
builder => { builder.HasMaxLength(64); }
);
});
}
}
What I am missing here. Your help will be highly appreciated. Thanks
Hi @nishadebrahim
This documentation can help you; Customizing the Application Modules: Extending Entities,
And also it will help while extending user interface; ASP.NET Core (MVC / Razor Pages) User Interface Customization Guide
You shouldn't add it to ApiMigrationsDbContext at all.
There is a point in the startup template that you can safely do it: YourProjectNameEfCoreEntityExtensionMappings
see the document: https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
Reopen if you have an issue.