2015-04-06 73 views
0

下面是實體,當我要添加遷移時,它給我例外。序列包含多個元素代碼第一次添加遷移

public class MyEntity 
    [Key] 
    public int ID { get; set; } 
public string Name { get; set; } 


[NotMapped] 
public HttpPostedFileBase DiagramFMCDocumentUpload { get; set; } 
//[ForeignKey("DiagramFMCDocumentID")] 
//public Document DiagramFMCDocument { get; set; } 
//public int? DiagramFMCDocumentID { get; set; } 

//[NotMapped] 
//public HttpPostedFileBase ExecutedDeedDocumentUpload { get; set; } 

public Document ExecutedDeedDocument { get; set; } 

[ForeignKey("ExecutedDeedDocument")] 
[InverseProperty("ExecutedDeedDocument")] 
public int? ExecutedDeedDocumentID { get; set; } 

[NotMapped] 
public HttpPostedFileBase DCertificationDocumentUpload { get; set; } 

public Document DCertificationDocument { get; set; } 

[ForeignKey("DCertificationDocument")] 
[InverseProperty("DCertificationDocument")] 
public int? DCertificationDocumentID { get; set; } 

////ForeignFundBasicType 
//public int ForeignFundStructureTypeFDID { get; set; } 

}

當我註釋掉一些文件& ForeignKey的領域,它完善了罰款,但比它不工作的罰款一個外鍵等等。這是例外。

System.InvalidOperationException: Sequence contains more than one element 
    at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass293.<>c__DisplayClass295.<FindRenamedIndexes>b__28b(String c) 
    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
    at System.Linq.Enumerable.SequenceEqual[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass293.<FindRenamedIndexes>b__28a(<>f__AnonymousType30`2 <>h__TransparentIdentifier286) 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(ModelMetadata source, ModelMetadata target, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) 
    at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
Sequence contains more than one element 
PM> Add-Migration First -Force 
System.InvalidOperationException: Sequence contains more than one element 
    at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass293.<>c__DisplayClass295.<FindRenamedIndexes>b__28b(String c) 
    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() 
    at System.Linq.Enumerable.SequenceEqual[TSource](IEnumerable`1 first, IEnumerable`1 second, IEqualityComparer`1 comparer) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass293.<FindRenamedIndexes>b__28a(<>f__AnonymousType30`2 <>h__TransparentIdentifier286) 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(ModelMetadata source, ModelMetadata target, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) 
    at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy`1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) 
    at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
+0

檢查前兩行: 在System.Linq.Enumerable .SingleOrDefault [TSource](IEnumerable'1源) 在System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer。<> c__DisplayClass293。<> c__DisplayClass295。 b__28b(串c) 特別是 「FindRenamedIndexes」 返回更然後是一個元素。你的實體以前的狀態是什麼? –

回答

1

什麼是您使用的EF版本?我猜你是使用較早版本比6.1.3

根據本issue,我想更新「實體框架」將解決您的問題

相關問題