实体框架5 - 抽象类型“X”没有映射的后代,因此无法映射 [英] Entity Framework 5 - The abstract type 'X' has no mapped descendents and so cannot be mapped

查看:181
本文介绍了实体框架5 - 抽象类型“X”没有映射的后代,因此无法映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在这个对象。有什么想法吗项目位于GitHub上,但您很有可能无法运行它,除非您有一个 FIX 服务器。我似乎无法上网这个错误信息。

I'm getting the following error when trying to operate on this object. Anybody got any ideas? The project is on GitHub, but you will most likely not be able to run it unless you have a FIX server laying around. I can't seem to internet this error message.

    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消息对象不是简单的DTO,他们不适合使用任何ORM映射到数据库。 QuickFix为每个FIX字段类型定义了一个不同的IField派生类。这意味着您必须将IField接口映射到数据库和每个单独的字段类型。

QuickFix Message object are not simple DTOs which makes them unsuitable for mapping to a database using any ORM. QuickFix defines a different IField-derived class for each FIX field type. This means that you will have to map both the IField interface to the database and each individual field type.

更糟糕的是,QuickFix / N是来自Java的端口,许多Javaism使映射非常困难,例如使用getter / setter方法代替属性。
另外一个障碍是每个FIX版本都有一个单独的命名空间,这意味着如果您想要保留所有FIX版本的邮件,您将必须映射具有相同类别的4-5个不同的命名空间。

To make matters worse, QuickFix/N is a port from Java with many Javaisms that make mapping very difficult, e.g. using getter/setter methods instead of properties. An additional obstacle is that there is a separate namespace for each FIX version, which means you will have to map 4-5 different namespaces with somewhat identical classes if you want to persist messages for all FIX versions.

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

A much better option is to create separate DTO objects which you can map to the database and convert from QuickFix Message object to your DTOs. Fortunately, QuickFix includes data dictionaries for various versions of FIX in XML form which you can use to generate your DTOs using a code generator.

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

To make conversion easier, you can use a convention-based tool like AutoMapper to convert QuickFix objects to your DTOs without writing the conversion code yourself.

这篇关于实体框架5 - 抽象类型“X”没有映射的后代,因此无法映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆