views:

59

answers:

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.

+1  A: 

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

ck
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.
Adrian