ASP. NET core EF core (Entity Framework 7) Database Update maintenance

Source: Internet
Author: User

Createdata-baseifnotexists, such as the previous API has been deprecated, is now using the Microsoft packaged, simplified, efficient API,migrations

Because the old API has to pay a high price, and the limitations

Open VS2017, select Tools->nutget Package Manager--Packages Manager console

1. Enter add-migration myfirstmigration instruction

The Migrations folders and files are automatically generated based on the current DbContext, which are used to create or extend a database that is specifically owned by the Migrations API.

Then in ASP. Startup.cs file, public void Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory Loggerfactory)

Configure this function, plus

2.update-database Upgrading the Database

[CSharp]View PlainCopyprint?
    1. using (var servicescope = app. Applicationservices.getrequiredservice<iservicescopefactory> (). Createscope ())
    2. {
    3. Servicescope.serviceprovider.getservice<unicornstorecontext> (). Database.migrate ();
    4. Servicescope.serviceprovider.getservice<applicationdbcontext> (). Database.migrate ();
    5. Servicescope.serviceprovider.getservice<unicornstorecontext> (). Ensureseeddata ();
    6. }


Replace your own function with the code above to

You can then generate a proprietary database of Mingrations APIs based on the files in the generated Mingrations folder, automatically scaling, and upgrading the database

Reprint: http://blog.csdn.net/loongsking/article/details/63682952

ASP. NET Core EF core (Entity Framework 7) database Update maintenance

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.