1

我浪费了几个小时来调试这个错误。当我的 EF Code First 生成一个新数据库时,它就会出现。原因是我最近创建了一个继承自我的一个实体中使用的复杂类型的类。实体没有引用后代类。这(对我来说)完全出乎意料的行为是如何解释的?

编辑:根据要求提供代码和堆栈跟踪。我必须更正我的声明,即仅在生成数据库时才抛出异常。每当第一次访问 dbcontext 时都会抛出它。删除 SpecializedComplexType 会使异常消失。

Public Class MyEntityWithComplexType
    Public Sub New()
        TheComplexType = New ComplexType
    End Sub
    'ID'
    Public Property ID As Long

    'NATIVE PROPERTIES'

    'NAVIGATION PROPERTIES'

    'COMPLEX TYPES'
    Public Property TheComplexType As ComplexType
End Class

Public Class ComplexType
    Public Property SomeValue As Integer
End Class

Public Class SpecializedComplexType
    Inherits ComplexType

    Public Property SomeAdvancedValue As Integer
End Class

System.Windows.Markup.XamlParseException 未处理
HResult=-2146233087 Message=De aanroep van de 构造函数在类型 BridgeItConverter.MainWindow dat overeenkomt 遇到 de opgegeven bindingsbeperkingen,heeft een uitzondering veroorzaakt。regelnummer 5 en regelpositie 5. Source=PresentationFramework LineNumber=5
Run(ExecutionContext executionContext, ContextCallback callback, Object state) bij System.Threading.ThreadHelper.ThreadStart() InnerException: System.ArgumentNullException HResult=-2147467261 Message=Waarde kan niet null zijn。Parameternaam:key Source=mscorlib ParamName=key StackTrace:bij System.Collections.Generic.Dictionary2.FindEntry(TKey key) bij System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value) bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.SortedEntityTypeIndex.Add(EdmEntitySet entitySet, EdmEntityType entityType) bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Analyze( ) bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Configure() bij System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) bij System.Data.Entity.ModelConfiguration.Configuration .ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) bij System.Data.Entity.DbModelBuilder。Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) bij System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) bij System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) bij System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) bij System.Data.Entity.Internal.LazyInternalContext.InitializeContext() bij System.Data.Entity.Internal.InternalContext.Initialize() bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) bij System.Data.Entity.Internal.Linq.InternalSet1.Initialize() bij System.Data.Entity.Internal.Linq.InternalSet 1.get_InternalContext() bij System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() bij System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) bij BridgeItConverter.MainWindow。 LoadData(BridgeItDB db) 在 C:\Users\andre_000\Documents\Visual Studio 2012\Projects\BridgeItDatabase\BridgeItConverter\MainWindow.xaml.vb:regel 233 bij BridgeItConverter.MainWindow..ctor() 在 C:\Users\andre_000\ Documents\Visual Studio 2012\Projects\BridgeItDatabase\BridgeItConverter\MainWindow.xaml.vb:regel 32 InnerException:

4

0 回答 0