>>>>>Try reading again.
>>>>>"To generate INSERT, UPDATE, or DELETE statements, the SqlCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata has been retrieved, such as after the first update, you should call the RefreshSchema method to update the metadata."
>>>>
>>>>I did read this line. However, it doesn't explain why will it use all columns to generate WHERE clause. What exactly does required metadata mean? Why it can not see that PK column I retrieve is a PK column?
>>>
>>>Your original select statement says "Select
every column. Therefore, when it builds the update sql it's going to update
every column because you told it to.
>>
>>What about the WHERE clause. Why does it construct it the way it does?
>>
>
>Because someone else may have updated the record between the time you read it and the time of your update
>
>Then this will fail. It won't find the record any more
>
>WHERE OtherColumns = @OriginalValue
Rob already pointed me out to extra documentation
http://msdn.microsoft.com/en-us/library/system.data.conflictoption(v=vs.110).aspxSo, I need to use the last option. However, for this purpose the PrimaryKey property has to be set. Apparently it is not set automatically and I am not sure how to set it for the generic class.
If it's not broken, fix it until it is.
My Blog