为什么Visual Studio DataSet Designer会生成如此复杂的查询?

时间:2013-07-10 20:35:16

标签: visual-studio tableadapter dataset-designer

我在MS Access数据库中有一个简单的表:

-------------------
| Programs        |
|-----------------|
| Id (PrimaryKey) |
| Name            |
| Path            |
| Notes           |
-------------------

然后使用Visual Studio向导生成相应的DataTableTableAdapter

生成的Select语句看起来与预期一致:

SELECT Id, Name, Path, Notes
FROM Programs

但生成的Update语句非常复杂:

UPDATE Programs
SET          Id = ?, Name = ?, Path = ?, Notes = ?
WHERE  (Id = ?) AND (? = 1) AND (Name IS NULL) AND (? = 1) AND (Path IS NULL) OR
                  (Id = ?) AND (? = 1) AND (Name = ?) AND (Path IS NULL) OR
                  (Id = ?) AND (? = 1) AND (Name IS NULL) AND (Path = ?) OR
                  (Id = ?) AND (Name = ?) AND (Path = ?)

为什么它如此复杂? 为什么它不简单,像这样:

UPDATE Programs
SET Id = ?, Name = ?, Path = ?, Notes = ?
WHERE  (Id = ?)

1 个答案:

答案 0 :(得分:4)

因为查询检测到自上次选择以来是否对数据库进行了更改。您可以将此类检查设置为简化查询。

从“TableAdapter配置向导”中选择“高级选项...”并取消选中“使用乐观并发”

请参阅http://msdn.microsoft.com/en-us/library/aa0416cz.aspx上的乐观并发(ADO.NET)