加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server-2012 – 带有SQL Server 2012的Entity Framework 6提

发布时间:2020-12-12 06:46:19 所属栏目:MsSql教程 来源:网络整理
导读:我有Visual Studio 2012,我正在使用EF 6的实体框架堆栈.我做的都正确但是在添加迁移时我收到了错误. System.Data.Entity.Core.ProviderIncompatibleException 这是课程 public class Order{ public virtual int OrderID { get; set; }} 上下文文件 public Sho
我有Visual Studio 2012,我正在使用EF 6的实体框架堆栈.我做的都正确但是在添加迁移时我收到了错误.

System.Data.Entity.Core.ProviderIncompatibleException

这是课程

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);
    }

和connctionstring的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: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. —> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. —>

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces,error: 26 – Error Locating Server/Instance Specified)

解决方法

试试这个.确保ShoppingCartContext所在的项目是启动项目,或者在执行add-migration命令时包含参数-startupprojectname ex. add-migration -startupprojectname yourprojectname

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读