I’m trying to make an easy query with my Entity Framework Core / .NET Core 7.0 in VB.NET:
Public Function GetOneRecord(idOne As Long, idTwo As Long) As Reply(Of Object)
Dim reply As New Reply(Of Object)
Try
reply.obj = db.Table.
Include("AnotherTable1").
Include("AnotherTable1.AnotherTable2").AsNoTracking().
Where(Function(a) a.SomeId = idOne AndAlso a.SomeIdTwo = idTwo).FirstOrDefault()
If (Not reply.obj Is Nothing) Then
reply.ok = True
' Everything its Ok
Else
reply.ToError("Couldn't find the record...")
End If
Catch ex As Exception
reply.ToError("Couldn't get the records correctly...")
End Try
Return reply
End Function
The query is working fine, every time I call that function, it works fine, the problem is that sometimes, the function returned
Couldn’t find the record…
It means, the record was not found, but is the same record I’m calling like 20-30 times before the code return it couldn’t find it.
So every 20 to 30 times (sometimes more, sometimes less), I try to get some record, it works fine but then, some of the callings just don’t get the record.
What should I do to fix this?
I don’t even know what the problem is, because the record does exist, and the function returned me the record correctly, it’s just one spontaneous query that did not “find” it.
This is happening to me with only this function, I’m not seeing this error with another function or query to the database (with my SQL Server and it fails with my Azure database too, so it’s not a database problem).
I’m getting all the database model with a Scaffold-DbContext
command on the console.
Sorry if my English is not good enough:/
I don’t know what to do, this error is just spontaneous…
5