Sql server 2012 带有SQL Server 2012的实体框架6提供System.Data.Entity.Core.ProviderIncompatibleException
我有Visual Studio 2012,我正在使用实体框架堆栈和EF 6。我做了所有正确的,但在添加迁移时,我得到了错误 System.Data.Entity.Core.ProviderIncompatibleException 这些是课程Sql server 2012 带有SQL Server 2012的实体框架6提供System.Data.Entity.Core.ProviderIncompatibleException,sql-server-2012,entity-framework-6,Sql Server 2012,Entity Framework 6,我有Visual Studio 2012,我正在使用实体框架堆栈和EF 6。我做了所有正确的,但在添加迁移时,我得到了错误 System.Data.Entity.Core.ProviderIncompatibleException 这些是课程 public class Order { public virtual int OrderID { get; set; } } 上下文文件 public ShoppingCartContext() : base("ShoppingCartDb")
public class Order
{
public virtual int OrderID { get; set; }
}
上下文文件
public ShoppingCartContext() : base("ShoppingCartDb")
{
Database.SetInitializer<ShoppingCartContext>(new DropCreateDatabaseAlways<ShoppingCartContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
#region Entity Framework 6 RC-1
modelBuilder.Properties().Where(x => x.Name == x.DeclaringType.ToString() + "ID")
.Configure(x => x.IsKey());
modelBuilder.Properties<DateTime>()
.Configure(x => x.HasColumnType("datetime2"));
#endregion
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
}
public ShoppingCartContext():base(“ShoppingCartDb”)
{
SetInitializer(新的DropCreateDatabaseAlways());
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
#区域实体框架6 RC-1
modelBuilder.Properties().Where(x=>x.Name==x.DeclaringType.ToString()+“ID”)
.Configure(x=>x.IsKey());
modelBuilder.Properties()
.Configure(x=>x.HasColumnType(“datetime2”);
#端区
modelBuilder.Conventions.Remove();
基于模型创建(modelBuilder);
}
以及ConctionString的web.config文件部分
<connectionStrings>
<add name="ShoppingCartDb"
connectionString="Server=Localhost;Database=ShoppingCartEfDb;User Id=sa;Password=xxxxxxxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
每当我尝试将迁移添加为以下内容时,都会出现错误:
System.Data.Entity.Core.ProviderIncompatibleException:从数据库获取提供程序信息时出错。这可能是由于实体框架使用了不正确的连接字符串造成的。有关详细信息,请检查内部异常,并确保连接字符串正确。-->System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。-->
System.Data.SqlClient.SqlException:建立到SQL Server的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。(提供程序:SQL网络接口,错误:26-定位指定的服务器/实例时出错)
试试这个。确保ShoppingCartContext所在的项目是启动项目,或者在执行添加迁移命令时包含参数-startupprojectname ex.add migration-startupprojectname yourprojectname您是否应该使用
base(“name=ShoppingCartDb”)
而不是base(“ShoppingCartDb”)
?将WebApi项目设置为“启动项目”是我问题的解决方案。抢手货