I have a small question about my project you could not know, I understand. But perhaps I have a very simple fault in my following function you could see?
<OperationContract()>
Public Function GetBestFahrer() As Autofahrer
Dim Database As New Model1Container
Dim Fahrer As Autofahrer = From d In Database.AutofahrerSet Where d.Unfälle = 0 Select d Order By d.Unfälle Ascending
If Fahrer Is Nothing Then
Fahrer = Autofahrer.CreateAutofahrer(0, "Testfahrer", DateTime.Now, 0)
Database.AutofahrerSet.AddObject(Fahrer)
Database.SaveChanges()
End If
Return Fahrer
End Function
Error message on line with “Dim Fahrer As Autofahrer = …”
Unable to cast object of type
‘System.Data.Objects.ObjectQuery`1[SilverlightApplication4.Web.Autofahrer]’
to type
‘SilverlightApplication4.Web.Autofahrer’.
Fahrer is a single object
From d In Database.AutofahrerSet Where d.Unfälle = 0 Select d Order By d.Unfälle Ascendingdoes not give you a single objectIt looks like you want to see if something exists and then create it if it doesn’t.
Try something like this