I’ve read through the posts here and can’t find any eureka answers so here’s what I have.
Linq to SQl not propagating a change back to the db.
Here’s my code. Does anything stand out?
The call to dc.GetChangeSet shows 0 changes.
What am I missing? I can see the new values from “setting” being set to the cs object properties. SettingID is a primary key in my table and shows as PK in the dbml so that’s not an issue.
Public Shared Function Update(ByVal setting As ClarifireSetup) As Boolean
Dim cs As ClarifireSetup
Try
Using dc As New AdminClarifireSetupDataContext(TripleDESSecurity.Decrypt(SharedData.PortalCnx))
cs = (From d In dc.AdminClarifireSetups
Where d.SettingID = setting.SettingID
Select New ClarifireSetup With {
.SettingID = d.SettingID,
.SettingKey = d.SettingKey,
.SettingValue = d.SettingValue,
.FriendlyName = d.FriendlyName,
.DisplayOrder = d.DisplayOrder
}).FirstOrDefault()
If cs IsNot Nothing Then
cs.SettingID = setting.SettingID
cs.SettingKey = setting.SettingKey
cs.SettingValue = setting.SettingValue
cs.FriendlyName = setting.FriendlyName
cs.DisplayOrder = setting.DisplayOrder
dc.GetChangeSet()
dc.SubmitChanges()
End If
End Using
Return True
Catch ex As Exception
Throw
Finally
If Not cs Is Nothing Then
cs.Dispose()
cs = Nothing
End If
End Try
End Function
Edit:
Changed my code to this, InsertOnSubmit shows 1 Insert, upon dc.SubmitChanges it errors due to cconflict. It’s trying to insert, not update…
Public Shared Function Update(ByVal setting As ClarifireSetup) As Boolean
Dim cs As AdminClarifireSetup
Try
Using dc As New AdminClarifireSetupDataContext(TripleDESSecurity.Decrypt(SharedData.PortalCnx))
'cs = (From d In dc.AdminClarifireSetups
' Where d.SettingID = setting.SettingID
' Select New AdminClarifireSetup With {
' .SettingID = d.SettingID,
' .SettingKey = d.SettingKey,
' .SettingValue = d.SettingValue,
' .FriendlyName = d.FriendlyName,
' .DisplayOrder = d.DisplayOrder
' }).FirstOrDefault()
cs = New AdminClarifireSetup
If cs IsNot Nothing Then
cs.SettingID = setting.SettingID
cs.SettingKey = setting.SettingKey
cs.SettingValue = setting.SettingValue
cs.FriendlyName = setting.FriendlyName
cs.DisplayOrder = setting.DisplayOrder
dc.SubmitChanges()
End If
End Using
Return True
Catch ex As Exception
Throw
Finally
If Not cs Is Nothing Then
cs = Nothing
End If
End Try
End Function
Try removing the custom class code and just select d.
My thinking is that the GetChangeSet is failing because it doesn’t see any native objects selected that are registering a change. You aren’t changing any names, so there’s no need to specify the explicit values that you’re narrowing down to.