从6.1.0更新到Entity Framework 6.1.1之后的异常

时间:2014-07-02 14:37:45

标签: c# entity-framework

我首先使用代码并具有类的结构。我有EntityDO类,描述所有实体。 MetadataEntityDO - 元数据描述类。许多类继承自MetadataEntityDO(例如AreaTemplateDO

public abstract class EntityDO
{
 //...
}

public abstract class MetadataEntityDO : EntityDO
{
 //...
}

public class AreaTemplateDO : MetadataEntityDO
{
 //...
}

DbContext中的映射配置:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<MetadataEntityDO>().Map(m =>
        {
            m.MapInheritedProperties();
            m.ToTable("MetadataEntity");
        });

        modelBuilder.Entity<AreaTemplateDO>().Map(m => m.ToTable("AreaTemplate"));
    } 

我将一些数据发送到数据库

    [Test]
    public void PAGiTMetadataContext_AddEntity_ChangeUpdateDateTime()
    {
        Guid guid = Guid.NewGuid();

        using (var dc = new PAGiTMetadataContext(testTimemanager, "TestEntityDatabase"))
        {
            dc.AreaTemplates.Add(new AreaTemplateDO() { ID = guid, Name = "Name", VersionCount = 1 });
            dc.SaveChanges();
            areaTemplate = dc.AreaTemplates.First(p => p.ID == guid);
        }
    }

在EF 6.1.0中,它工作正常,但在更新到6.1.1后,我得到了这个例外:

  

System.Data.Entity.Infrastructure.DbUpdateException:从ObjectStateEntry中检索值时出错。有关详细信息,请参阅内部异常   ----&GT; System.Data.Entity.Core.UpdateException:从ObjectStateEntry检索值时出错。有关详细信息,请参阅内部异常   ----&GT; System.Data.Entity.Core.MappingException:
  (265,10):错误3032:从第265,399行开始映射片段时出现问题:EntityTypes PAG.PAGiT.Data.AreaTemplateDO,PAG.PAGiT.Data.TemplateadditionlaAttributeDO,PAG.PAGiT.Data.BasicUnitDO,PAG.PAGiT.Data .TemplateConstraintDO,PAG.PAGiT.Data.TemplateScriptDO,PAG.PAGiT.Data.CatalogTemplateDO,PAG.PAGiT.Data.ConstantTemplateDO,PAG.PAGiT.Data.MaterialTemplateDO,PAG.PAGiT.Data.BasicOperationInOutTemplateDO,PAG.PAGiT.Data.BasicOperationTemplateDO ,PAG.PAGiT.Data.OperationTemplateDO,PAG.PAGiT.Data.PlantTemplateDO,PAG.PAGiT.Data.ProcessUnitTemplateDO,PAG.PAGiT.Data.RecipeElementDO,PAG.PAGiT.Data.RecipeElementInOutDO,PAG.PAGiT.Data.RecipeProcedureDO,PAG .PAGiT.Data.RecipeProcedureFormulaDO,PAG.PAGiT.Data.StringListDO,PAG.PAGiT.Data.UserTemplateDO,PAG.PAGiT.Data.WorkOrderTemplateDO被映射到表MetadataEntityDO中的相同行。映射条件可用于区分这些类型映射到的行。

     

结果StackTrace:
  在System.Data.Entity.Internal.InternalContext.SaveChanges()
  在System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
  在System.Data.Entity.DbContext.SaveChanges()
  在PAG.PAGiT.Data.PAGiTMetadataContext.SaveChanges()вc:\ WorkGitRep \ PAG.PAGiT \ PAG.PAGiT.Data \ PAGiTMetadataContext.cs:строка84
  在PAG.PAGiT.Data.IntegrationTest.PAGiTMetadataContextTest.PAGiTMetadataContext_AddEntity_ChangeUpdateDateTime()
  在c:\ WorkGitRep \ PAG.PAGiT \ PAG.PAGiT.Data.IntegrationTest \ PAGiTMetadataContextTest.cs:строка52

     

UpdateException

     

System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryToPropagatorResult(IEntityStateEntry stateEntry,Boolean useCurrentValues,ModifiedPropertiesBehavior modifiedPropertiesBehavior)
  在System.Data.Entity.Core.Mapping.Update.Internal.ExtractedStateEntry..ctor(UpdateTranslator 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)
  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)
  在System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions选项,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction)
  在System.Data.Entity.Core.Objects.ObjectContext。&lt;&gt; c__DisplayClass2a.b__27()
  在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func 1 operation)
в System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) в System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) в System.Data.Entity.Internal.InternalContext.SaveChanges() --MappingException в System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainerMapping entityContainerMap, Dictionary
2 resultDictionary)       System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer容器)       System.Data.Entity.Core.Common.Utils.Memoizer 2.<>c__DisplayClass2.<Evaluate>b__0() в System.Data.Entity.Core.Common.Utils.Memoizer 2.Result.GetValue()       System.Data.Entity.Core.Common.Utils.Memoizer 2.Evaluate(TArg arg) в System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection) в System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.InitializeEntitySet(EntitySetBase entitySetBase, MetadataWorkspace workspace) в System.Data.Entity.Core.Mapping.Update.Internal.ViewLoader.SyncInitializeEntitySet[TArg,TResult](EntitySetBase entitySetBase, MetadataWorkspace workspace, Func 2评估,TArg arg)       System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata..ctor(EntitySetBase entitySetBase,StructuralType type,UpdateTranslator translator)       System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.GetExtractorMetadata(EntitySetBase entitySetBase,StructuralType type)       System.Data.Entity.Core.Mapping.Update.Internal.ExtractorMetadata.ExtractResultFromRecord(IEntityStateEntry stateEntry,Boolean isModified,IExtendedDataRecord record,Boolean useCurrentValues,UpdateTranslator translator,ModifiedPropertiesBehavior modifiedPropertiesBehavior)       System.Data.Entity.Core.Mapping.Update.Internal.RecordConverter.ConvertStateEntryToPropagatorResult(IEntityStateEntry stateEntry,Boolean useCurrentValues,ModifiedPropertiesBehavior modifiedPropertiesBehavior)

有人知道怎么修理吗?

0 个答案:

没有答案