26 lines
1.5 KiB
C#
26 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using TIAM.Database.DbContexts.ServiceProviders;
|
|
using TIAM.Entities.Users;
|
|
|
|
namespace TIAM.Database.DbSets.Users;
|
|
|
|
public static class UserProductMappingDbSetExtensions
|
|
{
|
|
public static IQueryable<UserProductMapping> UserProductMappingsWithRelations(this IUserProductMappingDbSet ctx, bool autoInclude = true)
|
|
=> autoInclude
|
|
? ctx.UserProductMappings.Include(x => x.User).Include(x => x.Product)
|
|
: ctx.UserProductMappings;
|
|
|
|
|
|
public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId, bool autoInclude = true)
|
|
=> ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.Id == userProductMappingId);
|
|
|
|
public static UserProductMapping? GetUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId, bool autoInclude = true)
|
|
=> ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.UserId == userId && x.ProductId == productId);
|
|
|
|
public static IQueryable<UserProductMapping> GetUserProductMappingsByUserId(this IUserProductMappingDbSet ctx, Guid userId, bool autoInclude = true)
|
|
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.UserId == userId);
|
|
|
|
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true)
|
|
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId);
|
|
} |