Posts

Showing posts with the label Entity Framework

Entity Framework : How to generate model using Entity Framework Design

Image
This is a step-by-step walkthrough which will generate the Model using Entity Framework Designer and then generate a database schema from the model. The model is stored in a an EDMX file Pre-Requisities We need to have Visual Studio 2013 installed to complete this walkthrough.(You can use older version too like 2010 or 2012 to complete this tutorial.) Apart from that, You will also need to have NuGet installed on your Visual Studio. 1. Create new Application Steps : Create new Application Open Visual Studio, Click File → New → Project Click Console Application under templates → Visual C# → Windows Enter Name as ModelFirstApplication and Select OK 2. Create Model To create model, I will use Entity Framework Designer In Solution Explorer , Right Click on your Project and then Add New Item... Select Data from the left menu and then ADO.NET Entity Data Model Enter Name as Managing Context and click OK Now Se...

Entity Framework : How to create code using Existing Database

Image
This is a step-by-step walkthrough which will use existing database to create the model. We will create one console Application which will generate the model using existing databases. Pre-Requisities We need to have Visual Studio 2013 installed to complete this walkthrough.(You can use older version too like 2010 or 2012 to complete this tutorial.) Apart from that, You will also need to have NuGet installed on your Visual Studio and the 6.1 or later of the Entity Framework Tools . 1. Connect to an Existing Database Check here to see how can you connect to existing database. I have already created one database in my previous blog . I ll use the same database( CreateNewDatabase.ManagingContext ) to generate the model. 2. Create the Application Open Visual Studio, Click File → New → Project Click Console Application under templates → Visual C# → Windows Enter Name as CreateModelUsingExistingDatabase and Select OK 3. Reverse ...

Entity Framework : How to create database using code

Image
This is a step-by-step walkthrough which will create a new database using C# code. We will create one console Application which will create an empty database and will also add new tables too. Pre-Requisities We need to have Visual Studio 2013 installed to complete this walkthrough.(You can use older version too like 2010 or 2012 to complete this tutorial.) Apart from that, You will also need to have NuGet installed on your Visual Studio. Steps : 1. Create new Application Open Visual Studio, Click File -> New -> Project Click Console Application under templates -> Visual C# -> Windows Enter Name as CreateNewDatabase and Select OK 2. Create the Model Now we will create two simple model(Employee, Manager) using classes. As a part of demo I'll define both in Program.cs but in a real word application we should define in two separate file/classes. Add the following two classes in Program.cs. public class Manager ...