Visual Studio 中自动生成的 SQL 查询的质量

发布于 2024-07-16 11:20:17 字数 836 浏览 7 评论 0原文

我对自动生成的删除语句有疑问。 在我看来,删除本来应该是这样,

DELETE [tablename] where [PK] = @param

但它却生成了一个带有 4 个 OR 的查询。

DELETE FROM Market
WHERE     (@IsNull_Name = 1) 
AND (Name IS NULL) 
AND (@IsNull_Description = 1) 
AND (Description IS NULL) 
AND (MarketId = @Original_MarketId) 
OR
(@IsNull_Name = 1) 
AND (Name IS NULL) 
AND (Description = @Original_Description) 
AND (MarketId = @Original_MarketId) 
OR
(Name = @Original_Name) 
AND (@IsNull_Description = 1) 
AND (Description IS NULL) 
AND (MarketId = @Original_MarketId) 
OR
(Name = @Original_Name) 
AND (Description = @Original_Description) 
AND (MarketId = @Original_MarketId)

数据集工具几乎坚持进行涉及 PK/索引的查询,为什么它会生成如此复杂的代码?

这是“最佳实践”代码吗?如果是,有人可以引导我查看一些文档吗?

当然,简单的情况是 99% 需要的代码,另外 1% 应该是您需要编辑自动生成的代码或添加我们自己的代码的时候。

I was having an issue with the auto generated delete statement. In my mind the delete should have just been

DELETE [tablename] where [PK] = @param

but instead it generates a query with 4 ORs.

DELETE FROM Market
WHERE     (@IsNull_Name = 1) 
AND (Name IS NULL) 
AND (@IsNull_Description = 1) 
AND (Description IS NULL) 
AND (MarketId = @Original_MarketId) 
OR
(@IsNull_Name = 1) 
AND (Name IS NULL) 
AND (Description = @Original_Description) 
AND (MarketId = @Original_MarketId) 
OR
(Name = @Original_Name) 
AND (@IsNull_Description = 1) 
AND (Description IS NULL) 
AND (MarketId = @Original_MarketId) 
OR
(Name = @Original_Name) 
AND (Description = @Original_Description) 
AND (MarketId = @Original_MarketId)

The dataset tools almost insist on having queries involving PK/Indexes why does it generate such complex code?

Is this 'best practice' code, if it is can someone steer me to some documentation?

Surely the simple case is the 99% required code, the other 1% should be the times you need to edit the auto generated code or add our own.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分開簡單 2024-07-23 11:20:17

这是基于乐观并发 - 它需要在删除之前检查所有值是否相同。

This is based on optimistic concurrency - it needs to check all the values were the same before it does the delete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文