2013-12-18 29 views
4

我在ASP.NET MVC 4中有一個項目,我正在使用實體框架6.0.2數據持久性。在創建所有實體(「模型」)之後,使用數據註釋,我使用「遷移」來創建包,但是在SQL Server 2012中數據庫不是criano之後,顯示Nuget消息「序列不包含匹配元素」使用「遷移」實體框架6.0.2中的錯誤

「連接字符串」已配置,並且SQL Server 2012處於活動狀態。

我用命令:

PM> Enable-Migrations 


PM>Checking if the context targets an existing database... 
System.InvalidOperationException: Sequence contains no matching element 
    at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate) 
    at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name) 
    at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty column, EntityType table, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration) 
    at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass1.<Configure>b__0(Tuple`2 pm) 
    at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action) 
    at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration) 
    at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride) 
    at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride) 
    at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) 
    at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) 
    at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, 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.LazyInternalContext.get_ModelBeingInitialized() 
    at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) 
    at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w) 
    at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml) 
    at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) 
    at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) 
    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.ScaffoldInitialCreate(String language, String rootNamespace) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
Sequence contains no matching element 
+1

'Eneble-Migrations'我希望這是一個複製粘貼失敗或錯字 – Thewads

+0

你是否將任何數據從一個版本遷移到另一個?如果是這樣,你可以發佈該代碼嗎? – IronMan84

+0

這看起來像一個bug - 你可以使用https://entityframework.codeplex.com/WorkItem/Create來提交這個文件嗎?請提供一個repro。 – Pawel

回答

5

開始還以爲是在Visual Studio中的錯誤,甚至在課堂上或引用實體框架的安裝。 唯一的問題是「DOUBLE」屬性。正在使用錯誤的符號。 例如: 使用相反的:

 [Required(ErrorMessage = "Informe a Nota do Aluno")] 
     [Column("NotaAluno", TypeName = "Decimal(3,2)")] 
     [DisplayName("Nota do Aluno:*")] 
     public Double dNotaAluno { get; set; } 

使用此:

 [DisplayFormat(DataFormatString = "{0:n2}", 
      ApplyFormatInEditMode = true, 
      NullDisplayText = "Sem Nota")] 
     [Range(0, 100, ErrorMessage = "A nota deverá ser entre 0 a 100.")] 
     [Required(ErrorMessage = "Informe a Nota do Aluno")] 
     [Column("NotaAluno", TypeName = "decimal")] 
     [DisplayName("Nota do Aluno:*")] 
     public decimal dNota { get; set; } 

小問題,沒有注意在創造類的,尊重基本類型的SQL Server。 謝謝。

+10

任何人認爲「序列不包含匹配元素」的人缺乏足夠的關注是調試的充分錯誤信息。 –

1

我有一個類似的問題,試圖從SQL Server遷移到MySQL,我只是發現這是因爲使用datetime2。 sugested修復工作對我來說:使用普通的舊DateTime