var data = await dbContext.Set<OwnerData>().FromSqlRaw(@" SELECT [OWP].[OwnerProfileId], SELECT [OWP].[Email], FROM [user].[OwnerProfile] AS [OWP] CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance] INNER JOIN [user].[OwnerBalance] AS [OWB] ON [OWB].[OwnerProfileId] = [OWP].[OwnerProfileId] WHERE [ThirdPartyRefId] = {0}", ownerProfileId) .ToListAsync();Reescribo esto en una expresión linq como esta
var data = await _context.Set<OwnerProfile>() .Include(x => x.OwnerBalances) .Where(x => x.ThirdPartyRefId== ownerProfileId) .ToListAsync();no estoy seguro de cómo configurar esto
CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance]en consulta lambda
Sin tener definiciones de clase, es un poco difícil darle detalles, pero podría intentar agregar algo como:
var data = await _context.Set<OwnerProfile>() .Include(x => x.OwnerBalances) .Where(x => x.ThirdPartyRefId== ownerProfileId) .Select(x => new { x.Prop1, x.Prop2, CustomerBalance = x.CustomerBalance.Value != null ? x.CustomerBalance.Value : 0 }) .ToListAsync();También puede mover la declaración de selección fuera de la consulta:
var newData = data.Select(x => new { x.Prop1, x.Prop2, CustomerBalance = x.CustomerBalance.Value != null ? x.CustomerBalance.Value : 0 })Es posible que pueda usar el acceso condicional en la segunda versión, pero posiblemente no en la primera.