using Microsoft.EntityFrameworkCore;
using Prefab.Domain.Common;
namespace Prefab.Data.Queries;
///
/// Provides shared filters for working with generic attribute views.
///
public static class GenericAttributeViewQueries
{
///
/// Filters a module-specific view by entity identifier and key group.
///
public static IQueryable ForEntity(this IQueryable query, IEntity entity, string keyGroup)
where TView : class
{
if (entity == null)
{
throw new ArgumentNullException(nameof(entity));
}
if (string.IsNullOrEmpty(keyGroup))
{
throw new ArgumentException("KeyGroup cannot be null or empty.", nameof(keyGroup));
}
return query.Where(x => EF.Property(x, "EntityId") == entity.Id &&
EF.Property(x, "KeyGroup") == keyGroup);
}
}