Ends in:
7 DAYS
18 HRS
6 MIN
38 SEC
Ends in:
7 D
18 H
6 M
38 S
Open Closed

Saving null TenantId for entities #7746


User avatar
0
sgarad created
  • ABP Framework version: 8.2.1
  • UI Type: Angular
  • Database System: MySQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:
  • Hi There we have created below entity inheriting from IMultiTenant and AppService in DDD Module which is then referenced in Microservice.
[Table("venclass")]
public class Venclass : AggregateRoot<int>, IMultiTenant
{
    public Venclass()
    {
        
    }
    public Venclass(string classcode, string description, string user_entered)
    {
        this.class_code = classcode;
        this.description = description;
        this.date_entered = DateTime.Now;
        this.time_entered = DateTime.Now;
        this.user_entered = user_entered;
    }
    [Column("oid")]
    public override int Id { get; protected set; }

    [Column(TypeName = "varchar(4)" + CollationConst.collation)]
    [StringLength(VenclassConsts.Maxclass_codeLength, MinimumLength = VenclassConsts.Minclass_codeLength)]
    public virtual string class_code { get; set; }

    [Column(TypeName = "varchar(30)" + CollationConst.collation)]
    [StringLength(VenclassConsts.MaxdescriptionLength, MinimumLength = VenclassConsts.MindescriptionLength)]
    public virtual string description { get; set; }

    [DataType(DataType.Date)]
    [Column(TypeName = "Date")]
    public virtual DateTime? date_entered { get; set; }


    [Column(TypeName = "datetime")]
    public virtual DateTime? time_entered { get; set; }

    [Column(TypeName = "varchar(32)" + CollationConst.collation)]
    [StringLength(VenclassConsts.Maxuser_enteredLength, MinimumLength = VenclassConsts.Minuser_enteredLength)]
    public virtual string user_entered { get; set; }

    [Column("tenant_id")]
    public virtual Guid? TenantId { get; }

}
[Authorize(VendorManagementPermissions.VendorClass.Default)]
public class VenClassAppService : VendorManagementAppService, IVenClassAppService
{
    private readonly VenClassManager _vendorClassManager;
    private readonly IRepository<Venclass, int> _vendorClassRepository;
    public VenClassAppService(VenClassManager vendorClassManager, IRepository<Venclass, int> vendorClassRepository)
    {
        _vendorClassManager = vendorClassManager;
        _vendorClassRepository = vendorClassRepository;
    }       
    [Authorize(VendorManagementPermissions.VendorClass.Create)]
    public async Task<VenclassDto> CreateAsync(VenclassDto input)
    {
        var venclass = await _vendorClassManager.CreateAsync(
              input.class_code,
              input.description,                 
              input.user_entered
          );

        return ObjectMapper.Map<Venclass, VenclassDto>(venclass,input);
    }

    [Authorize(VendorManagementPermissions.VendorClass.Delete)]
    public async Task DeleteAsync(int id)
    {
        await _vendorClassRepository.DeleteAsync(id);
    }

    [Authorize(VendorManagementPermissions.VendorClass.Default)]
    public async Task<ListResultDto<VenclassDto>> GetAllAsync()
    {
        var venclass = await _vendorClassRepository.GetListAsync();
        return new ListResultDto<VenclassDto>(
            ObjectMapper.Map<List<Venclass>, List<VenclassDto>>(venclass)
        );
    }

    [Authorize(VendorManagementPermissions.VendorClass.Default)]
    public async Task<VenclassDto> GetAsync(int id)
    {
        return ObjectMapper.Map<Venclass, VenclassDto>(await _vendorClassRepository.GetAsync(id));
    }

    [Authorize(VendorManagementPermissions.VendorClass.Update)]
    public async Task<VenclassDto> UpdateAsync(VenclassDto input)
    {
        var venclass = await _vendorClassRepository.GetAsync(input.Id);

        ObjectMapper.Map(input, venclass);

        await _vendorClassRepository.UpdateAsync(venclass);

        return ObjectMapper.Map<Venclass, VenclassDto>(venclass);
    }
}

Module configuration

 public override void ConfigureServices(ServiceConfigurationContext context)
 {
     context.Services.AddAutoMapperObjectMapper<VendorManagementApplicationModule>();
     Configure<AbpAutoMapperOptions>(options =>
     {
         options.AddMaps<VendorManagementApplicationModule>(validate: true);
     });
    
     Configure<AbpMultiTenancyOptions>(options =>
     {
         options.IsEnabled = true;
         
     });   

 }
 public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
    var app = context.GetApplicationBuilder();
    app.UseMultiTenancy();
}

After runnig my app service create function TenantId is stored as null. Am I missing anything?


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ABP will try set tenant id, you need make sure there is a set modifier

  • User Avatar
    0
    sgarad created

    This is resolved. Thanks.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06