Files
prefab-page-detail/Prefab/Data/Queries/GenericAttributeViewQueries.cs
2025-10-27 17:39:18 -04:00

31 lines
957 B
C#

using Microsoft.EntityFrameworkCore;
using Prefab.Domain.Common;
namespace Prefab.Data.Queries;
/// <summary>
/// Provides shared filters for working with generic attribute views.
/// </summary>
public static class GenericAttributeViewQueries
{
/// <summary>
/// Filters a module-specific view by entity identifier and key group.
/// </summary>
public static IQueryable<TView> ForEntity<TView>(this IQueryable<TView> query, IEntity<Guid> 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<Guid>(x, "EntityId") == entity.Id &&
EF.Property<string>(x, "KeyGroup") == keyGroup);
}
}