Add an already existing table from an SQL to an already existing Entity Framework C# project - sql

Is there a way to "import" the already existing table from a DB that is already done by Entity Framework? The dev who created the table did it directly on the DB, not from EF. So is there a way, please?

Related

Upgrade existing database after making table changes to Entity Framework edmx file

I inherited an old c# project that used Entity Framework 4 to create the database. I need to add two new fields into a table, so I opened SQL Management Studio and added the new fields then ran a "Update model from database" in Visual Studio. It added my new fields.
The problem is many people have this c# program installed on their desktops with the older database (SQL Express installed on each machine locally). If I just send them an installer with this new schema, will it update their database automatically or do I need to call something in my code to update their database.
The code right now does
if (context.DatabaseExists())
{
//database exists, load what we need
}
else
{
context.CreateDatabase();
}
Do I need to call a context update or something if the databases don't match? Also I am worried about losing their data, I need the users existing data to still be there.

Change SQL Server Express LocalDB Database Structure in Visual Studio Project

I have a VS2013 project (WPF, C#), that has a .mdf database file that I use for the application. I'm using SQL Server 2012 Express LocalDB. I'm using Entity Framework 6.
I created the DB in the project by Add New Item -> Service-based Database.
I then added my tables with the appropriate columns, relationships and so forth.
I then added Add New Item -> ADO.NET Entity Data Model -> EF Designer from database, obviously selecting the database I created above.
Everything works great. So I deploy me application to end users using Flexera InstallShield.
Everything works.
So here is the question. If I make a structural change to the database (e.g. add a column to a table, or add a new table), how do I get this database change down to the end users database, that have already installed my application, without deleting or stepping on their existing data?
Thank you in advance.

Use SQL Server Management Studio to update code first project

I have created a project and added an Entity Data model using Code First from Existing Database.
Now, I like using SSMS (2008) to make changes like adding new columns, tables or changing some of the properties table or column properties.
Is there a way that I can make my changes in SSMS then have the Models and Migrations updated accordingly or once you have selected Code first and created you models are you stuck to only making changes in code and running the add migrations and update database from the package manager?
I also need to make sure when I publish the solution the server version of the database is updated accordingly.
Cheers in advance,
Kevin.

Changing Database Schema in the ASP.NET MVC4 Entity Framework Database First Application

I've a ASP.NET MVC4 EF DatabaseFirst Application. It's currently up & running. Now, I will have to make some changes to the Database Schema and re-deploy again. So when I make the DB Schema changes, how do I update the Model, and also which all files should I be updating.
Can someone point me to a tutorial for this.
Thanks
If you're using an ADO.NET entity data model, open up your Model.edmx, right-click anywhere and select Update Model from Database in the context menu.
If you've added new tables to the database you'll need to mark the checkbox "Tables" under the Add tab. If you've only modified existing tables, you can just press Finish straight away.

Handling database migrations when using Entity Framework

We are building an app in C# which uses Entity Framework with SQL Server 2008. We design the model using the designer in Visual Studio and auto-generate entities from this.
We're working on version 1.0. When we release 2.0, we'll need to make changes to the model and underlying database structure. I guess we need what's called "database migrations".
Traditionally, I've had a table in the database called something like 'version'. Whenever I've created a new version of my software, I've created database upgrade scripts containing ALTER TABLE statements. My software has checked the version table and run the upgrade scripts needed to upgrade the database to the 'software version'.
Is there some better way of handling this? It would be nice if I didn't have to write the alter table-scripts myself and write my own software to upgrade the database structure.
What I used to do when I did model first, is I pointed my model to a database that was purely for schema (so I had a myapp database, which was where my app ran, but my EF4 model was outputted to a myapp_schema database). When the myapp_schema was updated, I used Db Source Tools to generate the update scripts and make the myapp's database schema be the same as myapp_schema.
Chech this post out. It's about CTP4 of EF4, but it thing this is what you need.
http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
Unforunately this isn't yet available. CTP5 was released a few days ago and as far as I know this is not yet included.