0

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.

Learning
  • 8,029
  • 3
  • 35
  • 46
Mesh
  • 6,262
  • 5
  • 34
  • 53

1 Answers1

1

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

cjk
  • 45,739
  • 9
  • 81
  • 112
  • Now you've have said that the big query makes more sense. The issue I was having was that binding a FormView to a DataSource that uses the above delete statement - it didn't do the delete. Maybe the FV wasn't binding the correct values in the DeleteTemplate: - I'll check that out. – Mesh Apr 06 '09 at 08:21