SQL ADO.Net 实体 LINQ 问题
我有一个关于我的项目的小问题你不可能知道,我理解。但也许我在下面的函数中有一个非常简单的错误,你可以看到吗?
<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
错误消息显示“Dim Fahrer As Autofahrer = ...”
无法转换类型的对象 'System.Data.Objects.ObjectQuery`1[SilverlightApplication4.Web.Autofahrer]' 键入 'SilverlightApplication4.Web.Autofahrer'。
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'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Fahrer 是单个对象
From d In Database.AutofahrerSetWhere d.Unfälle = 0 Select d Order By d.Unfälle Ascending
不会给你一个单一的对象看起来你想看看某个东西是否存在,然后创建它如果它存在没有。
尝试这样的事情
Fahrer is a single object
From d In Database.AutofahrerSet Where d.Unfälle = 0 Select d Order By d.Unfälle Ascending
does 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