Код: Выделить всё
System.InvalidOperationException: The LINQ expression '__ids_0
.Contains(StructuralTypeShaperExpression:
Patron.Domain.RoleAggregate.Role
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Id.Value)' could not be translated.
Код: Выделить всё
public async Task GetRolesByIdsAsync(List roleIds)
{
var ids = roleIds.Select(id => id.Value).ToList();
return await dbContext.Roles
.Where(r => ids.Contains(r.Id.Value))
.ToListAsync();
}
Код: Выделить всё
public sealed class RoleId : AggregateRootId
{
private RoleId(Guid value) : base(value)
{
}
public static RoleId Create(Guid userId) =>
new(userId);
public static RoleId CreateUnique() =>
new(Guid.NewGuid());
public static ErrorOr Create(string value)
{
if (!Guid.TryParse(value, out var guid))
{
return Errors.Role.InvalidRoleId;
}
return new RoleId(guid);
}
}
Код: Выделить всё
public abstract class AggregateRootId : EntityId
{
protected AggregateRootId(TId value) : base(value)
{
}
}
Код: Выделить всё
public abstract class EntityId(TId value) : ValueObject
{
public TId Value { get; } = value;
public override IEnumerable GetEqualityComponents()
{
yield return Value;
}
public override string? ToString() => Value?.ToString() ??
base.ToString();
}
Я нашел решение, но оно очень некрасивое. и не оптимизирован (я хочу использовать LINQ):
Код: Выделить всё
public async Task GetListRoleByListId(List roleIds)
{
var roles = new List();
foreach (var role in await dbContext.Roles.ToListAsync())
{
foreach (var roleId in roleIds)
{
if (role.Id.Equals(roleId))
{
roles.Add(role);
}
}
}
return roles;
}
Код: Выделить всё
public async Task GetAsync(RoleId id) =>
await dbContext.Roles.FirstOrDefaultAsync(r => r.Id == id);
GitLab проекта:
https://gitlab .com/victor.nardel/training-project-ddd-clean-architecture
Проблему можно найти в ./Patron.Infrastructure/Persistence/Repositories/RoleRepository.cs
Подробнее здесь: https://stackoverflow.com/questions/784 ... translated