diff --git a/colaflow-api/src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/Persistence/Repositories/UserTenantRoleRepository.cs b/colaflow-api/src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/Persistence/Repositories/UserTenantRoleRepository.cs index f90cd09..dcbc04a 100644 --- a/colaflow-api/src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/Persistence/Repositories/UserTenantRoleRepository.cs +++ b/colaflow-api/src/Modules/Identity/ColaFlow.Modules.Identity.Infrastructure/Persistence/Repositories/UserTenantRoleRepository.cs @@ -1,4 +1,5 @@ using ColaFlow.Modules.Identity.Domain.Aggregates.Users; +using ColaFlow.Modules.Identity.Domain.Aggregates.Tenants; using ColaFlow.Modules.Identity.Domain.Repositories; using Microsoft.EntityFrameworkCore; @@ -18,9 +19,13 @@ public class UserTenantRoleRepository : IUserTenantRoleRepository Guid tenantId, CancellationToken cancellationToken = default) { + // Create value objects to avoid LINQ translation issues with .Value property + var userIdVO = UserId.Create(userId); + var tenantIdVO = TenantId.Create(tenantId); + return await _context.UserTenantRoles .FirstOrDefaultAsync( - utr => utr.UserId.Value == userId && utr.TenantId.Value == tenantId, + utr => utr.UserId == userIdVO && utr.TenantId == tenantIdVO, cancellationToken); } @@ -28,8 +33,11 @@ public class UserTenantRoleRepository : IUserTenantRoleRepository Guid userId, CancellationToken cancellationToken = default) { + // Create value object to avoid LINQ translation issues with .Value property + var userIdVO = UserId.Create(userId); + return await _context.UserTenantRoles - .Where(utr => utr.UserId.Value == userId) + .Where(utr => utr.UserId == userIdVO) .ToListAsync(cancellationToken); } @@ -37,9 +45,12 @@ public class UserTenantRoleRepository : IUserTenantRoleRepository Guid tenantId, CancellationToken cancellationToken = default) { + // Create value object to avoid LINQ translation issues with .Value property + var tenantIdVO = TenantId.Create(tenantId); + return await _context.UserTenantRoles - .Where(utr => utr.TenantId.Value == tenantId) - .Include(utr => utr.User) // Include user details for tenant management + .Where(utr => utr.TenantId == tenantIdVO) + // Note: User navigation is ignored in EF config, so Include is skipped .ToListAsync(cancellationToken); }