Publishing ASP MVC 5 code-first EF along with it's localdb - c#

I have an ASP MVC 5 application using Code First EF. I am setting up an environment to debug on a remote machine and follow these steps.
The website itself publishes fine, but I'm needing to publish the EF local databases along with it as well, content included. I've been digging around online but have had difficulty finding a step-by-step process for doing this that also allows for EF code first updates to the remote database.
Any help would be appreciated.

As for connection , try modifying the connection string in webConfig. As for the information, I'm not 100% sure on this, but I'd you think you would be able to backup the database and restore on the remote machine.
There is a _migrationHistory table in the database that EF refers to when checking the models against the database, so by restoring the whole database (and the _table as the result ) EF should not lose its state ( you won't need to run Update-Database).

If you publish to a server, you can use different appsettings for development and production using different web.config-files as described here
And for your database:
I pretend you want some content of your database being transferred into the production database in addition to get the right structure of tables too.
In this case, Migrations could do the job:
If you create your database with CodeFirstMigrations you can be sure, that your structure is right, by migrating the database before publishing.
And for the data, you can use a Database-Initializer to get the required data into any database your targeting as long you have enough permission for this.

Related

How can I Reverse Engineer Default Column Values that use scalar functions with EF Core?

I'm looking at upgrading our Storage Layer form Linq To Sql to EF Core 3.
I can reverse engineer the model from the database using the scaffolding command and it correctly creates FK fields who's default value is looked up using a Scalar Function called dbo.DefaultSystem()
But then I can't use EF Core to create a database from scratch because it can't scaffold programmability.
Is there, like, some kind of pre-create hook I can grab? Or better yet, a way to trigger code after the Systems table has been created.
Once Systems has been created I can just execute some SQL to create the DefaultSystem function.
I have to assume that there's logic in EF Core that knows it has to create the Systems table before it creates all the tables who have foreign keys pointing at it?
Update for comment from JDWeng
"You [create? - ed] the database first. What is your connection string? Are you connecting to a server (the server attached to an MDF file) or a LocalDb which is an MDF file?"
Source Connection String for Reverse Engineering:
#"Server=SQLDEV01\2008R2;Database=Database_Version_88;Trusted_Connection=True;"
Destination Connection String to test db.EnsureDeleted();db.EnsureCreated();
#"Server=(localdb)\mssqllocaldb;Database=LocalDevTest_Version_88;Trusted_Connection=True;"
So, the source database is hosted on a Windows Server running Sql Server 2008R2. This is our restricted schema design server which holds the design for our database. We create schema shapshots and upgrade scripts between the multiple database versions. This server is considered design gospel.
The target database is a (localdb)\mssqllocaldb which is created via EnsureCreated() from the DbContext generated by the Scaffold binaries.
I don't know much about the internals of this but according to your comment I'm just creating and connecting directly to an mdf file.
If there's nothing automatic to do this, I guess I'll have to create the database first with the System Of Record tables pre-created and configured and seeded.

Can't find my EF code first db

I know that there are some similar topic, but still I haven't found soultion.
I have create a simple ASP.NET MVC app with EF code first. I set no connectionstring, and everything works fine. I can perform CRUD actions and records are updated. But I don't know where my database is.
I am using Microsoft SQL Server Management Studio to connect to server. In Server name field I have tried to put: localhost, ., .\SQLEXPRESS, my Desktop name. These are all answears which I have found searching solutions.
Then in all cases I expand Databases/System Databases and all other Databases, but I can't find mine.
I know, that I can create an empty Database in Management Studio and set connectionstring to this DB (and it works), but I must send app to my teacher, and you know, he want to only click run, without setting up anything.
Have you got any solution?
Looked in yourproject/App_Data? Usually, the DB files are created there

How to use sqlite database on ubuntu server

I wanted to use sqlite on my server for my asp.net core application, but I'm having trouble undestanding how to communicate with it. There is no information about how to create a connection string for it, and I saw comments that it is not a server/client database type, but I see comments where people say they use sqlite on their servers, so my question is how do they do it?
I want to work on my project and build my database structure with code-first approach locally, push changes to the server and let the database work on the server. I added sqlite to my entity framework in the project with:
services.AddEntityFrameworkSqlite().AddDbContext<TetrominoContext>(options => options.UseSqlite(Configuration.GetConnectionString("SqliteConnection")));
But I don't know how to build the connection string.
If I were to create a db file on the ubuntu server then how do I specify path to that file in my application?
Connection strings in Microsoft.Data.Sqlite look like this:
Filename=/path/to/my.db

Local SQL Changes To SQL Azure Database

I have a local database I am working on for a website, I can publish the website changes to azure but cannot see an easy way to just get my 'changes' pushed up to SQL Azure.
I used this https://sqlazuremw.codeplex.com/ to initially get my local database onto Azure, but it seems to only support entire database migrations. Not minor changes like data, or a new field added?
This is my first time using Azure and it seems great, it's just this issue with the database which is now putting me off slightly.
I'm afraid that without any third-party tool you will not be able to achieve much.
What I usually do is create migration sql scripts and run them directly against the production database after the scripts have been thoroughly tested
If you manage your database schema using Visual Studio Database project then you can sync it with the SQL Azure database. I believe you can also sync data but I have not used that.

Best way to update CF app, db and server code

I've built a Compact Framework application to be used by delivery drivers. The system includes a WCF Service and SQL database on the server as well as a SQL CE database and CF application running on the mobile device.
Now the question is how to I update all this easily when I release new versions? The problems are:
it may be deployed to hundreds of PDAs
when first installed on a PDA the SQL CE database has to be populated. This can take a while. I don't want to have to do this each time the app is upgraded so I'm going to have to run scripts to update the db schema rather than just replacing the whole file and repopulating it.
the WCF service code will need to be updated
the SQL database schema will need to be updated
I can see solutions to all this but it seems like a lot of work. I thought it may be helpful to get a few tips before I launch into it all.
Thanks a lot
Mark
I've done some projects with more or less the same requierements.
it may be deployed to hundreds of PDAs
I'll recommend to use an updater, within the application. It checks via a webservice the availability of a new version. Download if theres an update. Then run another process to perform the update(This process I only use to run wceload.exe and then reboot the device).
when first installed on a PDA the SQL CE database has to be populated. This can take a while. I don't want to have to do this each time the app is upgraded so I'm going to have to run scripts to update the db schema rather than just replacing the whole file and repopulating it.
Don't include your database as a file for the application, create the scripts and check if the db exists if not create the db.
the WCF service code will need to be updated
I have an update webservice which is independent so the contract wont change. Which receives the current version, authentication and returns if the update is available and the url for the file to download.
You will need two different address to update and keep the other part working.Just perform a redirect in the new version.
the SQL database schema will need to be updated
I hope you mean that you refer to the server backend so I recommend to use views to search for the information.
If you mean to the SQLCE db you can ship patching scripts or plain erase the db and recreate the db.

Categories