Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Automatically filter data based on current tenant #3260


User avatar
0
SperseDev created

Hi,

I have simple data entity and appropriated dto entity

[Table("Packages", Schema = "Test")]
public class Package : FullAuditedEntity, IMustHaveTenant
{
	public int TenantId { get; set; }

	[Required]
	[MaxLength(50)]
	public string Name { get; set; }
}
[AutoMapFrom(typeof(Package))]
public class PackageDto : FullAuditedEntityDto
{
	public int TenantId { get; set; }

	public string Name { get; set; }
}

I have public (without authorization attribute) service:

public class PackageAppService : AppServiceBase, IPackageAppService
{
	private readonly IRepository<Package> _packageRepository;

	public PackageAppService(IRepository<Package> packageRepository)
	{
		_packageRepository = packageRepository;
	}

	public ListResultDto<PackageDto> GetAll()
	{
		var packages = _packageRepository.GetAll();

		return new ListResultDto<PackageDto>(ObjectMapper.Map<List<PackageDto>>(packages));
	}
}

When I call service method GetAll from host ( or public) context I receive list of all packages not filtered by tenantid null. When I use interface IMayHaveTenant instead of IMustHaveTenant all work correct. It's a bug?

Thanks.


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This is by design actually, you can read this section for more info <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Data-Filters#DocMustHaveTenant">https://aspnetboilerplate.com/Pages/Doc ... HaveTenant</a>.

    Thanks.