提问人:BedfordNYGuy 提问时间:6/12/2023 更新时间:6/13/2023 访问量:35
VS2022 服务器资源管理器和 SSMS 生成不同的查询结果
VS2022 Server Explorer and SSMS yield different query results
问:
我有一个 SQl 服务器查询定义如下:
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) ))
当我在 SSMS 中运行查询时,列标记返回所有 null。 当我在 VS2022 Server Explorer 中运行查询时,列标记显示正确的 json 字符串:
["topaz","peridot","emerald","silver","pierced"]
两个显示类别都显示为:
["Necklaces"]
为什么会有差异。我相信这就是我在 EFCore 中得到 NullReferenceException 的原因???
有什么建议吗?
雅 培
答:
0赞
BedfordNYGuy
6/13/2023
#1
我回去看到我正在测试的数据库与waws不同。 呃。像往常一样,操作员错误。 谢谢 雅 培
评论
nolock
read uncommitted
WITH (NOLOCK)