- Published on
How to Extend the Organization Unit Entity on AspNetZero
- Authors
- Name
- Oğuzhan Kırçalı
I use AspNetZero framework on my project. I see that Tenant, User and Role entities are abstract, but others are not abstract after I checked the document. I need to extend the organization unit entity to add an address column. I couldn't write the code immediately, but I started to change after read several issue and answers on the forums.
First of all, I created a class which has an inheritance from OrganizationUnit class.
using Abp.Organizations;
namespace MyProject.Organizations
{
public class MyOrganizationUnit : OrganizationUnit
{
public string Address { get; set; }
}
}
After dotnet ef migration add Add_Address_Column_To_OrganizationUnit
process, there was two new column in the migration file. The stranger one was called 'Discriminator'. This column put a flag the data which one created with OrganizationUnit or MyOrganizationUnit repository.
migrationBuilder.AddColumn<string>(
name: "Discriminator",
table: "AbpOrganizationUnits",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "Address",
table: "AbpOrganizationUnits",
nullable: false,
defaultValue: "");
After dotnet ef database update
process, I changed the repository with new organization unit class.
private readonly IRepository<MyOrganizationUnit, long> _organizationUnitRepository;
I run the project and checked the grids, there is no data about organization units. The problem was that discriminator column is empty. I updated Discriminator column of all rows with "MyOrganizationUnit" string value.
update dbo.AbpOrganizationUnits set Discriminator='MyOrganizationUnit'

Refresh the page. That's all.