Deploy EF Core SqlServer Database to Production Environment - entity-framework

Have developed new ASP.NET Core 1.1 MVC web site using Entity Framework Core and MSSQL LocalDB Server. I am new to the Entity Framework world as this is my first EF project. My production environment hosting provider creates an empty MSSQL database and then I must update that with whatever schema is needed. So how do I update or migrate the development schema into the empty production database on production server?
Is there someone or some document that can guide me thru this process. It would be much appreciated.
Orgbrat

Check con this MVA: https://mva.microsoft.com/en-US/training-courses/implementing-entity-framework-with-mvc-8931?l=e2H2lDC3_8304984382
I would recommend going over the whole course but you can focus on "Managing the Database" - "Code First Migrations". Hope this helps.

Related

ASP .Net Identity and Entity Framework Database

I'm developing an event page using entity framework and asp net identity 2.0 and I'm new also with this kind of tools.
If I create a new project that using template visual studio, it's automatically create a DB with several table. and also there are many code that I don't need in that template. (template -> project mvc with already installed authentication).
I've read several tutorial, but for creating from scratch my step is like this :
Create a DB
Create simple mvc project and install package nuget for asp net identity and EF framework
Set the connection strings
Create the code and EF will automatically created the table if not exist on DB?
I'm not really sure with number 4.. and are my steps are correct?
Thanks
Just follow the tutorial step by step, this will teach you how to create and build your project in a very simple way.
Getting started with ASP.NET Identity:
https://www.captechconsulting.com/blogs/Customizing-the-ASPNET-Identity-Data-Model-with-the-Entity-Framework-Fluent-API--Part-1
and here is a good Introduction to ASP.NET Identity:
http://tektutorialshub.com/asp-net-identity-tutorial-basics/

SQLite or SQL Server CE for Entity Framework migrations?

I'm starting a project and I will need to use the migrations provided by Entity Framework 6.
I found that SQLite does not have support for migrations.
SQL Server CE is the better option if I need to use the code-first migrations, or do I have other choices?
Remembering, I need a self-contained database engine.
No other choices, as far as I know

SQL Server Data Tools and Edmx

So we're using the new SSDT Microsoft released, pretty cool stuff. We are keeping a database project under version control with all the schemas, and an offline database for development and we can later deploy on SQL Azure database. We;re using EF in development, so my question is where would the edmx fit in, should we update the edmx file from the offline database or from the online SQL Azure directly, whats the best practice on this?
I would say that in your case "the production database is the truth", so I would update from SQL Azure. There's no right answer tho really.
Incidentally, in the early betas of SSDT it was possible to have a reference from an EDMX to a SSDT project thus your source code became the truth (which, in my opinion, is preferable) and the EDMX knew it was always working against "the truth". Unfortunately they ditched this feature and there are no signs of it returning.
For the EF to work correctly the EDMX file has to be in-synch with the database you are connecting to. It's hard to answer your question without knowing the development process you follow but I would imagine you use Sql Azure in production and develop against an on-premises database. Therefore one copy of the Edmx file will be used on production server. In the development environment you have a "living" copy of the edmx file that is changed as needed when the local database changes. When you get to the point you when you are ready to ship you deploy your app (include the edmx file) to a production environment that uses Sql Azure.
If, in your development environment, you update the edmx file from the SQL Azure then stuff will break or will not work correctly if the schema of the database in Azure is different from schema of your local database.

Deploying Devart EF Odata app to a Server - cannot find Framework Data Provider

I followed the simple tutorial # http://www.devart.com/dotconnect/oracle/articles/Tutorial_EF.html
(Which works perfectly, btw) combined with http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx for the OData part and now I need to deploy it to a server.
The problem I am having is that in step 4 of the devart tutorial, I chose a "Data Connection" to my database. Everything works fine on my dev box, but when I published the EF project, there was no reference to the DevArt dlls in the project. So, none were moved to the server.
And, of course this is producing a 'Unable to find the requested .Net Framework Data Provider. It may not be installed.'.
I tried just copying the dlls into the bin directory and I installed the devart product on the server. Neither worked.
I am used to ASP.Net applications that reference the needed Data dlls. What do I need to do to get my EF Odata service running?
The following page will explain how to deploy your EF devart project:
DevArt - Deployment

Deploy Entity Framework Code First

I guess I should have thought of this before I started my project but I have successfully built and tested a mini application using the code-first approach and I am ready to deploy it to a production web server.
I have moved the folder to my staging server and everything works well. I am just curious if there is a suggested deployment strategy?
If I make a change to the application I don't want to lose all the data if the application is restarted.
Should I just generate the DB scripts from the code-first project and then move it to my server that way?
Any tips and guide links would be useful.
Thanks.
Actually database initializer is only for development. Deploying such code to production is the best way to get some troubles. Code-first currently doesn't have any approach for database evolution so you must manually build change scripts to your database after new version. The easiest approach is using Database tools in VS Studio 2010 Premium and Ultimate. If you will have a database with the old schema and a database with the new schema and VS will prepare change script for you.
Here are the steps I follow.
Comment out any Initialization strategy I'm using.
Generate the database scripts for schema + data for all the tables EXCEPT the EdmMetadata table and run them on the web server. (Of course, if it's a production server, BE CAREFUL about this step. In my case, during development, the data in production and development are identical.)
Commit my solution to subversion which then triggers TeamCity to build, test, and deploy to the web server (of course, you will have your own method for this step, but somehow deploy the website to the web server).
You're all done!
The Initializer and the EdmMetadata tables are needed for development only.