2013-12-18 34 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