我有以下数据库-第一模型:
Imports System
Imports System.Collections.Generic
Partial Public Class User
Public Property ID As Integer
Public Property Username As String
Public Property Password As String
Public Property IsDisabled As Boolean
Public Property IsSuper As Boolean
Public Property MustChangePassword As Boolean
Public Property Notes As String
Public Overridable Property UserPermissions As ICollection(Of UserPermission) = New HashSet(Of UserPermission)
End Class和DB上下文
Partial Public Class Entities
Inherits DbContext
Public Sub New()
MyBase.New("name=Entities")
End Sub
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
Throw New UnintentionalCodeFirstException()
End Sub
.
.
.
Public Overridable Property Users() As DbSet(Of User)
.
.
.
End Class每当我运行以下查询时:
dim ent = New Entities()
result = (From u In ent.Users
Where u.ID = ID
Select u).SingleOrDefault()我得到以下错误:
“用户”不是'Transient.collectionConso_Model.Entity(Nullable=True,DefaultValue=的成员)。若要提取集合元素的属性,请使用子查询对集合进行迭代。接近转义标识符,第1行,第12列。
有线索吗?
发布于 2017-11-28 10:45:05
发现问题了!还有另一个名为Entity的EF类,其集合名为'Entities‘(类似于数据库上下文类)!
多么愚蠢的VB编译器没有对此发出任何警告!
https://stackoverflow.com/questions/47525895
复制相似问题