У меня есть объект, у которого есть объект значения диапазона дат, определенный как свойство.
Объект значения:
Код: Выделить всё
public record DateRange
{
private DateRange()
{
}
public DateOnly Start { get; init; }
public DateOnly? End { get; init; }
public int LengthInDays => End.HasValue ? End.Value.DayNumber - Start.DayNumber : int.MaxValue;
public static DateRange Create(DateOnly start, DateOnly? end)
{
if (start == default)
throw new ArgumentException("Start date cannot be empty.", nameof(start));
if (end.HasValue && start > end.Value)
throw new ApplicationException("End date precedes start date");
return new DateRange
{
Start = start,
End = end
};
}
public bool IsWithinRange(DateOnly date)
{
return date >= Start && (!End.HasValue || date x.ValidityDateRange);
Код: Выделить всё
var campaigns = await campaignRepository.Query()
.Where(c => c.ValidityDateRange.Start = currentDate)
.WhereIf(request.Title is not null, c => c.Title.Value == request.Title)
.WhereIf(request.Code is not null, c => c.Code.Value == request.Code)
.WhereIf(request.CategoryName is not null, c => c.CampaignCategory.Name.Value == request.CategoryName)
.WhereIf(request.TypeName is not null, c => c.CampaignType.Name.Value == request.TypeName)
.Include(c => c.CampaignCategory)
.Include(c => c.CampaignType)
.Include(c => c.Conditions)
.ThenInclude(cond => cond.ProductCategory)
.Include(c => c.Rewards)
.ThenInclude(reward => reward.ProductCategory)
.Include(c => c.Coupons)
.AsSplitQuery()
.ToListAsync(cancellationToken);
Выражение LINQ 'DbSet()
.Where(c => !(c.IsDeleted))
.Where(c => c.ValidityDateRange.Start = __currentDate_1)
.Where(c => c.Title.Value == __request_Title_2)' не удалось перевести. Либо перепишите запрос в форме, которую можно перевести, либо явно переключитесь на оценку клиента, вставив вызов AsEnumerable, AsAsyncEnumerable, ToList или ToListAsync. Дополнительную информацию см. на https://go.microsoft.com/fwlink/?linkid=2101038.
Подробнее здесь: https://stackoverflow.com/questions/792 ... eries-into