我有以下 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
这失败并出现以下错误(从荷兰语翻译,因此可能不是确切的消息): No Metadata found for EntityType CompetitionSubscriptionsLib.FullCompetitionSubscription。
由于FullCompetitionSubscription
该类装饰有<NotMapped>
属性,我可以理解错误消息,但重点DirectCast
是“出售”FullCompetitionSubscription
作为基础CompetitionSubscription
的DbContext
(如果我将类型更改为subscription
测试CompetitionSubscription
通过)。
我哪里错了?