31 lines
957 B
C#
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);
|
|
}
|
|
}
|