Visual Studio 中自动生成的 SQL 查询的质量
我对自动生成的删除语句有疑问。 在我看来,删除本来应该是这样,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是基于乐观并发 - 它需要在删除之前检查所有值是否相同。
This is based on optimistic concurrency - it needs to check all the values were the same before it does the delete.