Database created using EF in Visual Studio projects, subsequent update database operations (production already deployed, cannot delete database re-created)

Source: Internet
Author: User
Tags connectionstrings



Scenario: SharePoint Projects (other types of items are the same), the database was created with EF (version: 6.0.0.0), the production environment is already in use, so subsequent modifications to the database can only be achieved by updating.



Here's how to do it:



1. Visual Studio opens the project and opens the package management console.



How to: View--Other Windows--Package management Console






2, the project "References" in the EntityFramework.SqlServer.dll and EntityFramework.dll the properties of the two files to be copied to the local



How to: Select the file--Press "copy to local" in the f4--Properties dialog box and choose True





3. In the project configuration file, configure the database connection string.





 
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="ConnectName" connectionString="data source=111.111.111.111;initial catalog=TestDB;user id=sa;password=123;MultipleActiveResultSets=True;App=EntityFramework;Connect Timeout=3600;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>





4. Execute the following command in the "Package Management Console" order


Enable-Migrations
Add-Migration
Update-Database


5, all smooth, congratulations, the database updated successfully!



6, pay attention to the target platform of project generation, select "Any CPU".



How to do this: Select the item-Properties--in the Open Interface, change "target platform" to "any CPU"






7, after the completion of the update, it is best to make an appeal to modify the document, there is also the operation of the project in the new addition of the file to delete the good.






Database created using EF in Visual Studio projects, subsequent update database operations (production already deployed, cannot delete database re-created)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.