Entity framework 实体框架6.0.2中使用“0”时出错;“移民”;

Entity framework 实体框架6.0.2中使用“0”时出错;“移民”;,entity-framework,asp.net-mvc-4,migration,nuget,Entity Framework,Asp.net Mvc 4,Migration,Nuget,我有一个ASP.NETMVC4项目,我正在使用EntityFramework6.0.2进行数据持久化。在使用数据注释创建所有实体(“模型”)之后,我使用“迁移”来创建包,但是在SQL Server 2012中数据库不是criano之后,会显示Nuget消息“Sequence contains no matching element” 已配置“连接字符串”,并且SQL Server 2012处于活动状态 我使用命令: PM> Enable-Migrations PM>Checkin

我有一个ASP.NETMVC4项目,我正在使用EntityFramework6.0.2进行数据持久化。在使用数据注释创建所有实体(“模型”)之后,我使用“迁移”来创建包,但是在SQL Server 2012中数据库不是criano之后,会显示Nuget消息“Sequence contains no matching element”

已配置“连接字符串”,并且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
PM>启用迁移
PM>正在检查上下文是否以现有数据库为目标。。。
System.InvalidOperationException:序列不包含匹配元素
at System.Linq.Enumerable.Single[TSource](IEnumerable`1源,Func`2谓词)
位于System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest,字符串名称)
位于System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty列、EntityType表、DbProviderManifest providerManifest、Boolean allowOverride、Boolean fillFromExistingConfiguration)
在System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.c__DisplayClass1.b__0(元组'2pm)
在System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts,Action`1 Action)
位于System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable`1 propertyMappings,DbProviderManifest providerManifest,Boolean allowOverride,Boolean fillFromExistingConfiguration)
位于System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings,DbProviderManifest providerManifest,Boolean allowOverride)
位于System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping数据库映射、EntityType EntityType、DbProviderManifest providerManifest、Boolean allowOverride)
位于System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType EntityType、DbDatabaseMapping databaseMapping、DbProviderManifest providerManifest)
位于System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping,DbProviderManifest providerManifest)
位于System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping,DbProviderManifest providerManifest)
位于System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest,DbProviderInfo providerInfo)
位于System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
位于System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
位于System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput输入)
在System.Data.Entity.Internal.LazyInternalContext.InitializeContext()中
在System.Data.Entity.Internal.LazyInternalContext.get_ModelBeInInitialized()中
位于System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext上下文,XmlWriter编写器)
在System.Data.Entity.Utilities.DbContextensions.c_uuuDisplayClass1.b_uuu0(XmlWriter w)中
位于System.Data.Entity.Utilities.DbContextensions.GetModel(操作'1 writeXml)
位于System.Data.Entity.Utilities.DbContextensions.GetModel(DbContext上下文)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置,DbContext用户上下文)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置)
位于System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration MigrationConfiguration)
位于System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()处
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处
位于System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner)
位于System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(字符串语言,字符串根命名空间)
在System.Data.Entity.Migrations.EnableMigrationsCommand.c__DisplayClass2.b__0()中
位于System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(操作命令)
序列不包含匹配元素

最初认为这是Visual Studio中的bug,甚至是实体框架安装的类或引用中的bug。 唯一的问题是“双重”属性。使用了错误的符号。 前任: 而不是使用:

        [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的基本类型时缺乏注意。
谢谢。

我在尝试从sql server迁移到mysql时遇到了类似的问题,我发现这是因为使用了datetime2。建议对我有效的修复方法:使用普通的旧日期时间

电子表格迁移
我希望这是复制粘贴失败或输入错误。您是否将任何数据从一个版本迁移到另一个版本?如果是这样的话,你能发布代码吗?这看起来像是一个bug-你能用这个文件吗?请提供一个复制。缺乏注意的是那些认为“序列不包含匹配元素”是调试所需的足够错误信息的人。