C# 实体框架5-抽象类型';X';没有映射的子代,因此无法映射

C# 实体框架5-抽象类型';X';没有映射的子代,因此无法映射,c#,entity-framework,entity-framework-5,quickfix,fix-protocol,C#,Entity Framework,Entity Framework 5,Quickfix,Fix Protocol,我在尝试操作时遇到以下错误。有人有什么想法吗?在GitHub上,但是除非有一台服务器,否则很可能无法运行它。我似乎无法连接此错误消息 System.InvalidOperationException was unhandled by user code Message=The abstract type 'QuickFix.Fields.IField' has no mapped descendents and so cannot be mapped. Either remo

我在尝试操作时遇到以下错误。有人有什么想法吗?在GitHub上,但是除非有一台服务器,否则很可能无法运行它。我似乎无法连接此错误消息

    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

这是一条非常有用的错误消息

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

显然,您有一个抽象类(interface?
IField
),您正试图从您的上下文中获取这些抽象类的集合。当它是一个抽象类时,您需要有一个或多个派生类(由鉴别器列定义),以便EF能够具体化查询结果


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

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

更糟糕的是,QuickFix/N是一个来自Java的端口,有许多JavaISM使得映射非常困难,例如使用getter/setter方法而不是属性。 另一个障碍是,每个修复版本都有一个单独的名称空间,这意味着如果要为所有修复版本持久化消息,必须将4-5个不同的名称空间映射到一些相同的类

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

为了简化转换,您可以使用基于约定的工具(如将QuickFix对象转换为DTO),而无需自己编写转换代码