Init
This commit is contained in:
30
Prefab/Data/Queries/GenericAttributeViewQueries.cs
Normal file
30
Prefab/Data/Queries/GenericAttributeViewQueries.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user