Recreate database for database-first Entity Framework v6 and C# - c#

We made an app in C#; we used EF but have created the models using a database-first approach. We lost the database and need to recreate it in order to continue development; how do I use the model in my database-first C# app in order to automatically create the database in SQL Server (trying to avoid tedious database and table re-creation).
Thanks in advance,
Ronan

Related

How to scaffold SQL synonym using Entity Framework Core?

I have to use a synonym from external database in my application. Is it possible to scaffold a synonym using Entity Framework Core in database first approach? I've tried to pass a synonym name to -Tables switch while trying to scaffold, but an output in console told me "Unable to find a table in the database matching the selected table MY_SYNONYM." How to work with synonyms using EF Core?
In our circumstance we have replicated tables (using synonyms) to another DB from our ERP to lighten the load on the ERP for extra things like reporting. So I scaffolded the classes from the ERP itself and then pointed the context to the DB with the synonyms.
But to your question, 2 years later EF Core still does not appear support synonyms.

How to generate schema diagram from POCOs

I'm learning EF Core with SQL Server and trying to generate schema diagram among POCOs. I implemented the code-first approach and want to get a schema diagram shows each entity and relations.
I tried to generate the schema from Database Management Studio, but it doesn't contain navigation properties information. So, how to do that?
You can achieve that usually by creating a physical database using dotnet ef database update or other migration method and then using your db provider to reverse engineer the schema for you. For example, if you use SQL server, there is an option to create database schema in the SQL Management Studio UI. Other DBMS will likely have similar options.

Entity Framework 6.0 not showing newly added SQL Server table

I am developing an ASP.NET MVC 5 app with Entity Framework 6.0 in VS 2015 using a code-first approach. When I am adding a new model and migrate it, it's showing in DbContext and I am able to access it.
The problem is when I write a SQL query to create table (I don't need model for this because it is static data which is never going to be changed). After the update-database command, it's not showing up in context. If I create model and execute migrate command it is showing.
How to create a SQL Server table via query and access it in DbContext without creating models for it? Thanks in advance

Modify database schema via entity framework

I have an existing database and I am operating on data inside it via a .NET C# application using ADO.NET currently. I am suggested to use Entity Framework model. However, I want to add some stored procedures and tables to the database and use them when the compiled application runs. Can I create entity-framework model for current database without these to-be-added stored procedures and tables and then add those during runtime when using the compiled application?
Is it possible with entity framework model? Can someone give me some pointers about how to do this? I am new to entity framework.

Generate DDL Script to create database in Entity Framework

I am creating an application using Entity Framework code-first.
How can I create the database using this model? Is it possible to create the DDL scripts from a code-first approach just like the DDL scripts that can be generated from a model first approach?
Update : Generate a sql server script from Entity Framework code-first architecture
Using Entity Framework Code-First the application, when run, will create the database and tables that support your .Net model classes. Therefore using this approach you don't need DDL scripts as the work will be done for you by the application.
In Entity Framework there has been a lot of effort put into the Migrations tool to enable the deployment of db changes. This is detailed here:
Automatic Code First Migrations
Code First Migrations
This seems to offer the most effective way of deploying db changes to multiple target environments.
Code First is not particularly capable when it comes to local database deltas. If you are doing anything with OnModelCreating within your db context then this will require your database to be deleted then recreated by the code first application. This is required by code first to ensure that the code model and the persistence model are kept synchronised.
These are two good starter tutorials on MVC with an EF component.
Code-First Development with Entity Framework 4
Intro to ASP.NET MVC 3

Categories