Modify database schema via entity framework - c#

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.

Related

Recreate database for database-first Entity Framework v6 and 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

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

Javascript database with validation based on Entity Framework entities

Is there a way to synchronize local storage with Entity Framework?
What I'm thinking about is for example the following:
A user is completing a wizard in her browser. All necessary data is stored and validated localy based on the entities and validations defined in Entity Framework. In the last step, all this data is transfered from the browser to the server and saved to the database (by EF).
Is there a library for this? Is it even possible at all?
You could use Breeze. This will let you create entities in javascript and sync them with EF.

entity framework use code first on single new schema in existing database

I have a new project I am starting and I would like to use entity framework 6 code first to handle the database portion. The problem is, I do not have permissions to create a new database on the server I need to use. Because of this, I would like to create a new schema in an existing database and then have entity framework only interact with that specific schema. There are many other tables in other schema in the database that are related to other projects (none of which make use of entity framework in any way) and entity framework needs to leave them alone when it is creating/dropping/modifying tables related to my project.
Is that possible? If so, how do I go about setting that up?
It turns out this is actually pretty easy using EF6! In your context just override OnModelCreating and add
modelBuilder.HasDefaultSchema("schema_name");
before the call to
base.OnModelCreating(modelBuilder);

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