Refresh Mode does not work as I want

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Zero-G.
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Refresh Mode does not work as I want

Post by Zero-G. » Mon 14 Jun 2010 17:43

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 17 Jun 2010 13:36

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.

Zero-G.
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Thu 17 Jun 2010 14:39

OK....

But, the Refresh is still not working

THX

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 17 Jun 2010 14:42

Could you please provide the code sample illustrating your Refresh() usage?

Zero-G.
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Thu 17 Jun 2010 15:42

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 23 Jun 2010 11:25

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.

Post Reply