| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Diagnostics;
- using Quadarax.Application.QLiberace.Common.Domain;
- using Quadarax.Application.QLiberace.Common.Entities.Base;
- using Quadarax.Foundation.Core.Data;
- using Quadarax.Foundation.Core.Data.Domain;
- using Quadarax.Foundation.Core.Data.Extensions;
- using Quadarax.Foundation.Core.Data.Interface;
- using Quadarax.Foundation.Core.Data.Interface.Domain;
- namespace Quadarax.Application.QLiberace.Common.Repositories
- {
- public abstract class QlbrcTenantCodeTrackedRepository<TEntity> : QlbrcTrackedRepository<TEntity> where TEntity : QlbrcEntityTenantCode, new()
- {
- protected string? TenantCode => OperationContext.GetContext<QlbrcContext>().TenantCode;
- protected QlbrcTenantCodeTrackedRepository(IUnitOfWork<IDataDomain> unitOfWork, QlbrcContext operationContext) : base(unitOfWork, operationContext)
- {
- }
- public override IQueryable<TEntity> Query(IPaging paging,bool usingUncommited=false)
- {
- var result = base.Query(paging, usingUncommited).Where(x => Equals(x.TenantCode ,TenantCode));
- #if DEBUG
- Debug.WriteLine($"Repo '{GetType().Name}' Query returns {result.Count()} rows.");
- #endif
- return result;
- }
- public override TEntity Get(long id)
- {
- return Query(new Paging()).MultiInclude(DefaultIncludes.ToArray()).FirstOrDefault(x => Equals(x.Id, id) && Equals(x.TenantCode,TenantCode))!;
- }
- public override IQueryable<TEntity> Get(IEnumerable<long> ids)
- {
- return Query(new Paging()).Where(x => ids.Contains(x.Id) && Equals(x.TenantCode,TenantCode));
- }
- public override TEntity New()
- {
- var entity = base.New();
- entity.TenantCode = TenantCode!;
- return entity;
- }
- }
- }
|