【问题标题】:Entity Framework 5 - The abstract type 'X' has no mapped descendents and so cannot be mapped实体框架 5 - 抽象类型“X”没有映射的后代,因此无法映射
【发布时间】:2012-09-21 20:51:37
【问题描述】:

我在尝试对 this object 进行操作时遇到以下错误。有人有什么想法吗? project 在 GitHub 上,但你很可能无法运行它,除非你周围有一个 FIX 服务器。我似乎无法上网此错误消息。

    System.InvalidOperationException was unhandled by user code
      Message=The abstract type 'QuickFix.Fields.IField' has no mapped descendents and so cannot be mapped. Either remove 'QuickFix.Fields.IField' from the model or add one or more types deriving from 'QuickFix.Fields.IField' to the model. 
      Source=EntityFramework
      StackTrace:
           at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.GetEntityTypeMappingInHierarchy(DbDatabaseMapping databaseMapping, EdmEntityType entityType)
           at System.Data.Entity.ModelConfiguration.Edm.Services.AssociationTypeMappingGenerator.GenerateIndependentAssociationType(EdmAssociationType associationType, DbDatabaseMapping databaseMapping)
           at System.Data.Entity.ModelConfiguration.Edm.Services.AssociationTypeMappingGenerator.Generate(EdmAssociationType associationType, DbDatabaseMapping databaseMapping)
           at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateAssociationTypes(EdmModel model, DbDatabaseMapping databaseMapping)
           at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel model)
           at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.GenerateDatabaseMapping(EdmModel model, DbProviderManifest providerManifest)
           at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
           at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
           at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
           at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
           at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
           at System.Data.Entity.Internal.InternalContext.Initialize()
           at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
           at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
           at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
           at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
           at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
           at System.Data.Entity

【问题讨论】:

    标签: c# entity-framework entity-framework-5 quickfix fix-protocol


    【解决方案1】:

    QuickFix Message 对象不是简单的 DTO,这使得它们不适合使用任何 ORM 映射到数据库。 QuickFix 为每个 FIX 字段类型定义了不同的 IField 派生类。这意味着您必须将 IField 接口映射到数据库和每个单独的字段类型。

    更糟糕的是,QuickFix/N 是 Java 的一个端口,其中包含许多使映射非常困难的 Javaism,例如使用 getter/setter 方法而不是属性。 另一个障碍是每个 FIX 版本都有一个单独的命名空间,这意味着如果你想为所有 FIX 版本持久化消息,你必须映射 4-5 个不同的命名空间和一些相同的类。

    更好的选择是创建单独的 DTO 对象,您可以将其映射到数据库并将 QuickFix 消息对象转换为您的 DTO。幸运的是,QuickFix 包含各种 XML 格式的 FIX 版本的数据字典,您可以使用代码生成器生成 DTO。

    为了使转换更容易,您可以使用AutoMapper 等基于约定的工具将 QuickFix 对象转换为您的 DTO,而无需自己编写转换代码。

    【讨论】:

      【解决方案2】:

      现在这是一个非常有用的错误消息。

      抽象类型“QuickFix.Fields.IField”没有映射的后代,因此无法映射。从模型中删除“QuickFix.Fields.IField”或将一种或多种派生自“QuickFix.Fields.IField”的类型添加到模型中。

      显然你有一个抽象类(接口?)IField,你正试图从你的上下文中获取这些的集合。当它是一个抽象类时,您需要拥有一个或多个派生类(由鉴别器列定义),EF 才能实现查询结果。

      如果是接口,则不应映射接口,而应映射实现它的类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-09
        • 1970-01-01
        • 2011-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-07
        相关资源
        最近更新 更多