Entity framework &引用;“未为属性指定映射”;在EF中的复杂类型上具有只读属性

Entity framework &引用;“未为属性指定映射”;在EF中的复杂类型上具有只读属性,entity-framework,Entity Framework,我有一个DbContext和一个包含EF复杂类型的类的DbSet,而EF复杂类型又包含一个只读属性。我在运行应用程序时遇到以下错误: error 3004: Problem in mapping fragments starting at line 6: No mapping specified for properties Frobnitzer.ComplexPropIdWrap in Set Frobnitzers. An Entity with Key (PK) will not roun

我有一个DbContext和一个包含EF复杂类型的类的DbSet,而EF复杂类型又包含一个只读属性。我在运行应用程序时遇到以下错误:

error 3004: Problem in mapping fragments starting at line 6:
No mapping specified for properties Frobnitzer.ComplexPropIdWrap in Set Frobnitzers.
An Entity with Key (PK) will not round-trip when:
Entity is type [ef_complex_pk.Frobnitzer]
问题到底是什么。在上可用的最小测试用例-运行唯一的单元测试以获取错误

顺便说一句,这是一个非常简化的测试用例,所以对您来说可能是显而易见的,但当它与一个有各种流畅配置的大型项目混合在一起时,它肯定不是


完全错误:

System.Data.Entity.Infrastructure.DbUpdateException was unhandled by user code
  HResult=-2146233087
  Message=Error retrieving values from ObjectStateEntry. See inner exception for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Internal.InternalContext.SaveChanges()
       at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
       at System.Data.Entity.DbContext.SaveChanges()
       at ef_complex_pk.TestRunner.RunIt() in C:\repo\ef-complex-pk\ef-complex-pk\TestRunner.cs:line 18
  InnerException:
       HResult=-2146233087
       Message=Error retrieving values from ObjectStateEntry. See inner exception for details.
       Source=EntityFramework
       StackTrace:
            at System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryToPropagatorResult(IEntityStateEntry stateEntry, Boolean useCurrentValues, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
            at System.Data.Entity.Core.Mapping.Update.Internal.ExtractedStateEntry..ctor(UpdateTranslator translator, IEntityStateEntry stateEntry)
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.LoadStateEntry(IEntityStateEntry stateEntry)
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.PullModifiedEntriesFromStateManager()
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
            at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
            at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
            at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
            at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
            at System.Data.Entity.Internal.InternalContext.SaveChanges()
       InnerException:
            HResult=-2146232032
            Message=
(6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties Frobnitzer.ComplexPropIdWrap in Set Frobnitzers.
An Entity with Key (PK) will not round-trip when:
  Entity is type [ef_complex_pk.Frobnitzer]

            Source=EntityFramework
            StackTrace:
                 at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainerMapping entityContainerMap, Dictionary`2 resultDictionary)
                 at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer container)
                 at System.Data.Entity.Core.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
                 at System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()
                 at System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg)
                 at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection)
                 at System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.InitializeEntitySet(EntitySetBase entitySetBase, MetadataWorkspace workspace)
                 at System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.SyncInitializeEntitySet[TArg,TResult](EntitySetBase entitySetBase, MetadataWorkspace workspace, Func`2 evaluate, TArg arg)
                 at System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata..ctor(EntitySetBase entitySetBase, StructuralType type, UpdateTranslator translator)
                 at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.GetExtractorMetadata(EntitySetBase entitySetBase, StructuralType type)
                 at System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata.ExtractResultFromRecord(IEntityStateEntry stateEntry, Boolean isModified, IExtendedDataRecord record, Boolean useCurrentValues, UpdateTranslator translator, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
                 at System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryToPropagatorResult(IEntityStateEntry stateEntry, Boolean useCurrentValues, ModifiedPropertiesBehavior modifiedPropertiesBehavior)
            InnerException:
用户代码未处理System.Data.Entity.Infrastructure.DbUpdateException HResult=-2146233087 消息=从ObjectStateEntry检索值时出错。有关详细信息,请参见内部异常。 Source=EntityFramework 堆栈跟踪: 位于System.Data.Entity.Internal.InternalContext.SaveChanges()处 在System.Data.Entity.Internal.LazyInternalContext.SaveChanges()中 位于System.Data.Entity.DbContext.SaveChanges()处 在C:\repo\ef complex pk\ef complex pk\TestRunner.cs中的ef_complex_pk.TestRunner.RunIt()处:第18行 内部异常: HResult=-2146233087 消息=从ObjectStateEntry检索值时出错。有关详细信息,请参见内部异常。 Source=EntityFramework 堆栈跟踪: 位于System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryTopPropagatorResult(IEntityStateEntry stateEntry stateEntry、Boolean useCurrentValues、ModifiedProperties Behavior ModifiedProperties Behavior) 位于System.Data.Entity.Core.Mapping.Update.Internal.ExtractedStateEntry..ctor(UpdateTranslator translator translator,IEntityStateEntry stateEntry) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.LoadStateEntry(IEntityStateEntry stateEntry) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.PullModifiedEntriesFromStateManager()处 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()处 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()处 位于System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator ut) 位于System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult,Func`2 updateFunction) 位于System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()处 位于System.Data.Entity.Core.Objects.ObjectContext.b__35() 在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 Func,IDBEcutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess) 位于System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions选项、IDBEcutionStrategy executionStrategy、Boolean startLocalTransaction) 在System.Data.Entity.Core.Objects.ObjectContext.c__DisplayClass2a.b__27()中 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1操作)中 位于System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions选项,布尔值executeInExistingTransaction) 位于System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions) 位于System.Data.Entity.Internal.InternalContext.SaveChanges()处 内部异常: HResult=-2146232032 信息= (6,10):错误3004:映射从第6行开始的片段时出现问题:未为集合Frobnitzers中的属性Frobnitzer.ComplexPropidRap指定映射。 具有密钥(PK)的实体在以下情况下不会往返: 实体类型为[ef_complex_pk.Frobnitzer] Source=EntityFramework 堆栈跟踪: 位于System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainerMappingEntityContainerMapping,Dictionary`2 resultDictionary) 位于System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer容器) 位于System.Data.Entity.Core.Common.Utils.Memoizer`2.c_uuudisplayClass2.b_uuu0() 位于System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()处 at System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg) 位于System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase区段、MetadataWorkspace工作区、StorageMappingItemCollection StorageMappingItemCollection) 位于System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.InitializeEntitySet(EntitySetBase EntitySetBase,MetadataWorkspace工作区) 在System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.SyncInitializeEntitySet[TArg,TResult](EntitySetBase EntitySetBase,MetadataWorkspace工作区,Func`2 evaluate,TArg arg) 位于System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata..ctor(EntitySetBase EntitySetBase,StructuralType,UpdateTranslator translator translator) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.GetExtractorMetadata(EntitySetBase EntitySetBase,StructuralType) 位于System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata.ExtractResultFromRecord(IEntityStateEntry stateEntry,Boolean isModified,IExtendedDataRecord,Boolean useCurrentValues,UpdateTranslator translator translator,ModifiedProperties行为ModifiedProperties行为) 位于System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryTopPropagatorResult(IEntityStateEntry stateEntry stateEntry、Boolean useCurrentValues、ModifiedProperties Behavior ModifiedProperties Behavior) 内部异常:
复杂类型中的属性至少需要有一个受保护的setter,以便EF可以加载该值

你可以找到一个固定的前男友