DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/CrudWellRelatedRepositoryBase.cs

46 lines
1.5 KiB
C#
Raw Normal View History

using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2024-08-19 10:01:07 +05:00
namespace AsbCloudInfrastructure.Repository;
2024-08-19 10:01:07 +05:00
public class CrudWellRelatedRepositoryBase<TDto, TEntity> : CrudRepositoryBase<TDto, TEntity>, IRepositoryWellRelated<TDto>
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
where TEntity : class, IId, IWellRelated
{
public CrudWellRelatedRepositoryBase(IAsbCloudDbContext context)
: base(context) { }
2024-08-19 10:01:07 +05:00
public CrudWellRelatedRepositoryBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
: base(context, makeQuery) { }
2024-08-19 10:01:07 +05:00
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
{
var entities = await GetQuery()
.Where(e => e.IdWell == idWell)
.AsNoTracking()
.ToArrayAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
{
if (!idsWells.Any())
return Enumerable.Empty<TDto>();
2022-06-15 14:57:37 +05:00
2024-08-19 10:01:07 +05:00
var entities = await GetQuery()
.Where(e => idsWells.Contains(e.IdWell))
.AsNoTracking()
.ToArrayAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
}