C# 商店类型';瓦查尔(100)和#x27;在SqlServer提供程序清单中找不到
我正在从事一个MVC4项目,该项目使用EF6执行与数据库(SQL Server)之间的所有操作。我必须进行一些重构,以使用更明确的Fluent API。基本上,现在项目中的每个实体都有对应于所有映射的Fluent API代码 当我试图从PackageManager控制台运行EF命令时,问题就出现了。这就是我得到的错误: 在SqlServer提供程序清单中找不到存储类型“Varchar(100)” 这是错误的完整日志:C# 商店类型';瓦查尔(100)和#x27;在SqlServer提供程序清单中找不到,c#,sql-server,asp.net-mvc,entity-framework,entity-framework-6,C#,Sql Server,Asp.net Mvc,Entity Framework,Entity Framework 6,我正在从事一个MVC4项目,该项目使用EF6执行与数据库(SQL Server)之间的所有操作。我必须进行一些重构,以使用更明确的Fluent API。基本上,现在项目中的每个实体都有对应于所有映射的Fluent API代码 当我试图从PackageManager控制台运行EF命令时,问题就出现了。这就是我得到的错误: 在SqlServer提供程序清单中找不到存储类型“Varchar(100)” 这是错误的完整日志: PM> enable-migrations Checking if th
PM> enable-migrations
Checking if the context targets an existing database...
System.InvalidOperationException: The store type 'Varchar(100)' could not be found in the SqlServer provider manifest
at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty column, EntityType table, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass47_0.<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.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, ICollection`1 entitySets, 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.GetModel(Action`1 writeXml)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
at System.Data.Entity.Infrastructure.Design.Executor.CreateMigrationScaffolder(DbMigrationsConfiguration configuration)
at System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInitialCreateInternal(DbConnectionInfo connectionInfo, String contextTypeName, String contextAssemblyName, String migrationsNamespace, Boolean auto, String migrationsDir)
at System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInitialCreate.<>c__DisplayClass0_0.<.ctor>b__0()
at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)
PM>启用迁移
正在检查上下文是否以现有数据库为目标。。。
System.InvalidOperationException:在SqlServer提供程序清单中找不到存储类型“Varchar(100)”
位于System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest,字符串名称)
位于System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty列、EntityType表、DbProviderManifest providerManifest)
在System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.c__DisplayClass47_0.b__0(元组`2pm)
在System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts,Action`1 Action)
位于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,ICollection`1 entitySets,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.GetModel(操作'1 writeXml)
位于System.Data.Entity.Migrations.Dbmigator..ctor(DbMigrationsConfiguration配置、DbContext usersContext、DatabaseExistenceEstate ExistenceEstate、称为DbyCreateDatabase的布尔值)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置)
位于System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration MigrationConfiguration)
位于System.Data.Entity.Infrastructure.Design.Executor.CreateMigationsCafFolder(DbMigrationsConfiguration配置)
位于System.Data.Entity.Infrastructure.Design.Executor.ScaffolInitialCreateInternal(DbConnectionInfo connectionInfo、String contextTypeName、String contextAssemblyName、String MigrationNamespace、Boolean auto、String migrationsDir)
在System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInitialCreate.c__DisplayClass0_0.b__0()中
在System.Data.Entity.Infrastructure.Design.Executor.OperationBase.c__DisplayClass4_0`1.b__0()中
位于System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(操作)
我已经读了很多博客/帖子如何解决这个问题,但似乎没有一个有效。以下是我尝试过的几件事:
public class EntityA: BaseEntity
{
/// <summary>
/// Gets or sets Contact identifier
/// </summary>
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
}
公共类实体a:BaseEntity
{
///
///获取或设置联系人标识符
///
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共bool IsActive{get;set;}
}
在单独的类中使用Fluent API配置:
public class EntityAConfiguration : EntityTypeConfiguration<EntityA>
{
public EntityAConfiguration()
{
this.ToTable("EntityA")
.HasKey(c => c.Id);
this.Property(c => c.Id)
.HasColumnName("Id")
.HasColumnType("int")
.IsRequired();
this.Property(c => c.Name)
.HasColumnName("Name")
.HasColumnType("Varchar(40)")
.IsRequired();
this.Property(c => c.Description)
.HasColumnName("Description")
.HasColumnType("Varchar(100)")
.IsRequired();
this.Property(c => c.IsActive)
.HasColumnName("IsActive")
.HasColumnType("bit");
}
}
公共类EntityConfiguration:EntityTypeConfiguration
{
公共实体配置()
{
本表为ToTable(“实体A”)
.HasKey(c=>c.Id);
this.Property(c=>c.Id)
.HasColumnName(“Id”)
.HasColumnType(“int”)
.IsRequired();
this.Property(c=>c.Name)
.HasColumnName(“名称”)
.HasColumnType(“Varchar(40)”)
.IsRequired();
this.Property(c=>c.Description)
.HasColumnName(“说明”)
.HasColumnType(“Varchar(100)”)
.IsRequired();
this.Property(c=>c.IsActive)
.HasColumnName(“IsActive”)
.HasColumnType(“bit”);
}
}
BaseEntity类只有两个属性:CreatedDate、UpdateDate。我在所有需要存储该信息的实体中使用该类
public EntityAConfiguration()
{
this.ToTable("EntityA")
.HasKey(c => c.Id);
this.Property(c => c.Id)
.HasColumnName("Id")
.HasColumnType("INT")
.IsRequired();
this.Property(c => c.Name)
.HasColumnName("Name")
.HasColumnType("VARCHAR")
.HasMaxLength(40)
.IsRequired();
this.Property(c => c.Description)
.HasColumnName("Description")
.HasColumnType("VARCHAR")
.HasMaxLength(100)
.IsRequired();
this.Property(c => c.IsActive)
.HasColumnName("IsActive")
.HasColumnType("bit");
}