I have a SQl Server query defined as follows:
SELECT ROW_NUMBER() OVER (ORDER BY p.SKU) AS Id,
p.Id AS ProductId,
p.SKU,
'ImageURL' AS ImageURL,
p.Name AS ProductName,
p.FullDescription AS Description,
p.Price,
p.ProductCost,
p.StockQuantity,
JSON_QUERY(stuff((select ',"' + STRING_ESCAPE(Name, 'json') + '"'
FROM dbo.Product_ProductTag_Mapping ptm
INNER JOIN dbo.ProductTag pt
ON pt.Id = ptm.ProductTag_Id
WHERE ptm.Product_Id = p.Id
for xml path(''), type
).value('.', 'nvarchar(max)'), 1, 1, '[') + ']') Tags,
JSON_QUERY(stuff((select ',"' + STRING_ESCAPE(Name, 'json') + '"'
FROM dbo.Product_Category_Mapping pcm
INNER JOIN dbo.Category ca
ON ca.Id = pcm.CategoryId
WHERE pcm.ProductId = p.Id
for xml path(''), type
).value('.', 'nvarchar(max)'), 1, 1, '[') + ']') Categories
FROM dbo.Product AS p WITH (NOLOCK)
INNER JOIN
dbo.Product_Category_Mapping AS pcmo WITH (NOLOCK) ON p.Id = pcmo.ProductId
INNER JOIN
dbo.Product_Picture_Mapping AS ppm WITH (NOLOCK) ON p.Id = ppm.ProductId
WHERE (p.Published = 1 AND p.StockQuantity > 0 AND p.Price > 0 AND p.IsGiftCard = 0
-- This is for duplicate records in testing
AND( p.Id IN (SELECT DISTINCT MIN(Id) FROM dbo.Product GROUP BY SKU) ))
When I run the query in SSMS, the column tags returns all nulls. When I run the query in VS2022 Server Explorer the column tags displays the proper json string:
["topaz","peridot","emerald","silver","pierced"]
Both display categories as:
["Necklaces"]
Why the discrepancy. I believe this is why I'm getting a NullReferenceException in EFCore???
Any suggestions?
Abbott
1条答案
按热度按时间gv8xihay1#
I went back and saw that the db I was testing against waws different. Uggh. As usual, operator error. Thanks Abbott