Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 实体框架代码首次迁移是否绑定到特定DBMS?_.net_Sql Server_Entity Framework_Sql Server Ce_Entity Framework Migrations - Fatal编程技术网

.net 实体框架代码首次迁移是否绑定到特定DBMS?

.net 实体框架代码首次迁移是否绑定到特定DBMS?,.net,sql-server,entity-framework,sql-server-ce,entity-framework-migrations,.net,Sql Server,Entity Framework,Sql Server Ce,Entity Framework Migrations,更新:在我再次删除并重新创建迁移SQL Server之后,没有错误。因此,初始提供者似乎编码在模型快照的某个地方 更新: 我没有意识到这一点,但实体框架代码第一次迁移似乎绑定到特定的DBMS。我在演示应用程序SQL Server Compact Edition 4.0中使用了它,并将其迁移到SQL Server 2014 Express LocalDB SQL Server中的数据库架构创建正确,但当我尝试读取或写入数据库时,会出现以下错误 未找到具有固定名称“System.Data.SqlS

更新:在我再次删除并重新创建迁移SQL Server之后,没有错误。因此,初始提供者似乎编码在模型快照的某个地方

更新:

我没有意识到这一点,但实体框架代码第一次迁移似乎绑定到特定的DBMS。我在演示应用程序SQL Server Compact Edition 4.0中使用了它,并将其迁移到SQL Server 2014 Express LocalDB

SQL Server中的数据库架构创建正确,但当我尝试读取或写入数据库时,会出现以下错误

未找到具有固定名称“System.Data.SqlServerCe.4.0”的ADO.NET提供程序的实体框架提供程序

我现在不在任何地方使用SQL Server CE,所有NuGet软件包都已卸载,提供程序已从
App.Config
中删除

app.config

dbo._迁移历史记录


现在,当我删除dbo.\u MigrationHistories表时,错误消失了。我是否需要重新创建迁移以寻址SQL Server而不是SQL Server CE

NewCustomerIsCreated.cs

[TestMethod]
public void NewCustomerIsCreated()
{
var customerLastName=customerLastName待删除;
//安排
var systemUnderTest=新的CarRentalBusinessLayer();
var customerToBeCreated=\u autoFixture.Build()
.Without(property=>property.CustomerId)
.With(property=>property.CustomerType,CustomerModel.Consumer)
.With(property=>property.LastName,customerLastName).Create();
var expectedResult=customerToBeCreated;
//表演
systemUnderTest.CreateNewCustomer(customerToBeCreated.FirstName、customerToBeCreated.LastName、customerToBeCreated.DateOfBirth、customerToBeCreated.Street、customerToBeCreated.City、customerToBeCreated.Postcode、,
customerToBeCreated.CustomerType);
//断言
客户实际结果;
使用(var carRentalDbContext=new carRentalDbContext(_connectionString))
{
actualResult=carRentalDbContext.Customers.SingleOrDefault(c=>c.LastName==customerLastName);
}
Assert.IsTrue(actualResult!=null&&expectedResult.LastName==actualResult.LastName);
}

OP的反馈:

在我重新创建迁移之后,没有错误。看起来提供者真的是 在模型快照中的某处编码

原始答案:

是的,您必须这样做。这意味着您必须
删除
\uu MigrationHistory
表上的数据,并需要
重新创建它

如果您看到下图,您可以看到
ProductVersion
列。这就是运行时错误的原因

更新:这是EF版本

 <package id="EntityFramework" version="6.1.3" targetFramework="net461" />


“现在,当我删除dbo.\u MigrationHistory表时,错误消失了。”-这没有意义。EF是否实际访问数据库?什么是初始值设定项?但是,我知道EF在更新参考资料时遇到了一些问题。您确定所有连接都是SqlConnections,并且指定的连接字符串指向正确的提供程序吗?@DevilSuichiro是的,您是对的。这没有任何意义,可能是我犯了一些错误,但我不知道这一点。我现在重新检查了指向正确提供程序的连接字符串,我将更新问题以使其更清楚。基本构造函数采用连接字符串/DbConnection,ContextOwnsConnection。当您使用base(newsqlconnection(connectionString),true)时会发生什么?什么是CarRentalDbInitializer()?@DevilSuichiro我将使用默认构造函数检查它,仍然不清楚我使用SqlServer Ce的存储位置before@DevilSuichiro我添加了视频以可视化问题。我还删除了默认构造函数,该构造函数显然不做任何更改,但ProductVersion的确切含义是什么?ProductVersion使用的是EF版本。请参阅
更新
部分。但是,我不知道该数据库会如何干扰数据库连接-我的意思是,在执行第一个Db调用之前,它甚至不是目标。让我们来看看。
<?xml version="1.0" encoding="utf-8"?>
<connectionStrings>
  <clear/>
  <add name="CarRentalDb" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=CarRentalDb;Integrated Security=True;multipleactiveresultsets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
public class CarRentalDbContext : DbContext
{
    public CarRentalDbContext()
        //only used until development, will not be checked in
        : base(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=CarRentalDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")
    {
        Database.SetInitializer(new CarRentalDbInitializer());
    }

    public CarRentalDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
    {
        Database.SetInitializer(new CarRentalDbInitializer());
    }
}
    [TestMethod]
    public void NewCustomerIsCreated()
    {
        var customerLastName = CustomersLastNameToBeDeleted;

        //Arrange
        var systemUnderTest = new CarRentalBusinessLayer();
        var customerToBeCreated = _autoFixture.Build<CustomerModel>()
                                              .Without(property => property.CustomerId)
                                              .With(property => property.CustomerType, CustomerModel.Consumer)
                                              .With(property => property.LastName, customerLastName).Create();
        var expectedResult = customerToBeCreated;

        //Act
        systemUnderTest.CreateNewCustomer(customerToBeCreated.FirstName, customerToBeCreated.LastName, customerToBeCreated.DateOfBirth, customerToBeCreated.Street, customerToBeCreated.City, customerToBeCreated.Postcode,
            customerToBeCreated.CustomerType);

        //Assert
        Customer actualResult;
        using (var carRentalDbContext = new CarRentalDbContext(_connectionString))
        {
            actualResult = carRentalDbContext.Customers.SingleOrDefault(c => c.LastName == customerLastName);
        }
        Assert.IsTrue(actualResult != null && expectedResult.LastName == actualResult.LastName);
    }
 <package id="EntityFramework" version="6.1.3" targetFramework="net461" />