扩展实体并使用独立实体



我们正在使用 ASP.NET Zero/BoilerPlate,并且在扩展非抽象实体并使用独立实体访问数据时遇到了以下问题。

我已将组织单位实体扩展到组织单位,以便可以添加一些其他属性,即:

public class OrganisationUnit : OrganizationUnit
{
public virtual bool IsCompany { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="OrganisationUnit"/> class.
/// </summary>
public OrganisationUnit()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="OrganisationUnit"/> class.
/// </summary>
/// <param name="tenantId">Tenant's Id or null for host.</param>
/// <param name="displayName">Display name.</param>
/// <param name="parentId">Parent's Id or null if OU is a root.</param>
public OrganisationUnit(int? tenantId, string displayName, long? parentId = null) : base(tenantId, displayName, parentId)
{
}
}

但是,当我们尝试使用独立实体时,没有结果,例如:

public class OrganisationUnitManager : IDomainService
{
private readonly IRepository<OrganisationUnit, long> _organisationUnitRepository;
private readonly IRepository<Abp.Organizations.OrganizationUnit, long> _organizationUnitRepository;
public OrganisationUnitManager(IRepository<OrganisationUnit, long> organisationUnitRepository, IRepository<Abp.Organizations.OrganizationUnit, long> organizationUnitRepository)
{
_organisationUnitRepository = organisationUnitRepository;
_organizationUnitRepository = organizationUnitRepository;
}
public async Task<Abp.Organizations.OrganizationUnit> GetOUForEmployee(Employee.Employee employee)
{
var orgUnit = _organisationUnitRepository.FirstOrDefault(ou => ou.Id == employee.OrganizationUnitId);
var orgS = _organisationUnitRepository.GetAll(); // Returns 0 Results - with the extended columns
var orgZ = _organizationUnitRepository.GetAll(); // Returns All Records in AbpOrganizationUnits without the extended columns.
return orgUnit;
}
}

我试图在GetOUForEmployee中做的是找到组织单位,而不是组织单位。但是什么也没找到。用。GetAll(( 突出了这个问题,因为此处的 IRepository 没有在扩展表上返回任何结果。

您需要将新的 DbSet 添加到 DbContext 中。并添加迁移。

public class AbpZeroTemplateDbContext : AbpZeroDbContext<Tenant, Role, User, AbpZeroTemplateDbContext>, IAbpPersistedGrantDbContext
{
//...
public virtual DbSet<OrganisationUnit> MyOrganizationUnits { get; set; }
//...
}

扩展组织单位的步骤

  • 创建一个从组织单位继承的新类,如扩展组织单位
  • 将扩展组织单元的新数据库集添加到数据库上下文中。
  • 添加
  • 已添加的迁移
  • 更新数据库(已成功查看更改(

见 https://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=11109&hilit=extend

最新更新