Page 1 of 1
Refresh Mode does not work as I want
Posted: Mon 14 Jun 2010 17:43
by Zero-G.
Hey
Using the latest Version of dotConnect for mySQL
I have a table with one entity, which has AutoGenerated Value Option = True.
I insert a new Row of data with Linq and then I call the Refresh Method, so I get the autogenerated value, but this ends up with an error, that the entity cannot be NULL.
Please help - THX
Posted: Thu 17 Jun 2010 13:36
by AndreyR
The simpler way to get the Auto Generated Value is to set the AutoSync property to OnIsert. In this case the property value will be refreshed immediately after SubmitChanges is called.
Posted: Thu 17 Jun 2010 14:39
by Zero-G.
OK....
But, the Refresh is still not working
THX
Posted: Thu 17 Jun 2010 14:42
by AndreyR
Could you please provide the code sample illustrating your Refresh() usage?
Posted: Thu 17 Jun 2010 15:42
by Zero-G.
My code:
Code: Select all
Try
Cursor.Current = Cursors.WaitCursor
Try
bsArtikelstamm.EndEdit()
Dim Details = From Query In LinqProvider.GetFirmendaten(True) Select Query
Dim ArtikelstammDetails As Artikelstammdetail
Dim Artikelstamm As Artikelstamm = bsArtikelstamm.Current
Artikelstamm.Icode = Nothing
Artikelstamm.Datseit = "1900-12-31"
SuchString = Artikelstamm.Artikelnr
For Each Detail As Firmendaten In Details
ArtikelstammDetails = New Artikelstammdetail With {.Firmenid = Detail.Id}
Artikelstamm.Artikelstammdetails.Add(ArtikelstammDetails)
Next
myDataContext.Artikelstamms.InsertOnSubmit(Artikelstamm)
LinqProvider.SaveDataContext(myDataContext)
Catch ex As Exception
If ex.InnerException.ToString.Contains("Duplicate Entry") = True Then
IntelliSoft.myMessageBox.OfficeBox.Show("Der von Ihnen eingegebene Artikel existiert bereits!", _
LinqProvider.MessageCaption, MessageBoxButtons.OK, _
IntelliSoft.myMessageBox.OfficeMessageBoxIcon.Error)
bsArtikelstamm.CancelEdit()
bsArtikelstamm.ResetBindings(False)
Else
IntelliSoft.myMessageBox.OfficeBox.Show("Folgender Fehler ist aufgetreten: " & _
ex.Message, LinqProvider.MessageCaption, _
MessageBoxButtons.OK, IntelliSoft.myMessageBox.OfficeMessageBoxIcon.Error)
End If
End Try
Finally
myDatacontext.Refresh()
Cursor.Current = saveCursor
End Try
Posted: Wed 23 Jun 2010 11:25
by AndreyR
The
DataContext.Refresh() method should be called with RefreshMode specified, and a set of entities should be passed as parameter of this call.
I recommend you to specify the objects you want to be refreshed from database explicitly. Please let me know if anything goes wrong.