我有以下POCO课程:
Public Class CompetitionSubscription
Public Property ID As Long
Public Overridable Property CompetitionID As Long
Public Overridable Property CompetitionPlayerID As Long
Public Property CompetitionStrength As Short?
Public Property StrengthWithinSection As Short?
End Class
<NotMapped()>
Public Class FullCompetitionSubscription
Inherits CompetitionSubscription
Public Property Competition As Competition
Public Property CompetitionPlayer As CompetitionPlayer
End Class
只有一个表格的DbContext:
Public Class CompetitionSubscriptionsDB
Inherits DbContext
Public Property CompetitionSubscriptions As DbSet(Of CompetitionSubscription)
End Class
我写过这样的单元测试:
<TestMethod()>
Public Sub AddSubscriptionToDatabase()
Using db = New CompetitionSubscriptionsDB
Dim subscription = New FullCompetitionSubscription With
{.CompetitionID = 1,
.CompetitionPlayerID = 1,
.CompetitionStrength = 2,
.StrengthWithinSection = 12}
db.CompetitionSubscriptions.Add(DirectCast(subscription, CompetitionSubscription))
db.SaveChanges()
End Using
End Sub
这失败了以下错误(翻译自荷兰语,所以可能不是确切的消息): 未找到EntityType CompetitionSubscriptionsLib.FullCompetitionSubscription 的元数据。
由于FullCompetitionSubscription
类使用<NotMapped>
属性进行装饰,我可以理解错误消息,但DirectCast
的要点是“卖出”FullCompetitionSubscription
CompetitionSubscription
的基数DbContext
(如果我将subscription
的类型更改为CompetitionSubscription
,则测试通过。)
我哪里出错了?