Posts

Showing posts with the label Entity Framework

Entity Framework Step By Step 3 – Model First

Image
As I have discussed in my previous post we know how to create a Database using Entity Framework Model First framework. In this post we’ll see how to read & write data using EF. When you create the Database using the designer, entity classes which we can use to access the data will be automatically generated in your solution. Please see the highlighted classes in the screen shot below. BloggingModel.Context.cs :- Represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit. Blog.cs & Post.cs :- Entity classes with properties defined in the database table. Writing Data static void WriteData()       {           using (var db = new BloggingContext())           {             ...

Entity Framework Step By Step 2 – Model First

Image
We’ll see how we can user Model First Development workflow of Entity framework with a very simple example in step by step so you can easily understand the concept. Pre-Requisites 1. You will need to have Visual Studio 2010 or Visual Studio 2012 installed to complete this walkthrough. 2. If you are using Visual Studio 2010, you will also need to have NuGet installed. Step 1:  Create Application 1. Create New Console Application. 2. Name it as “ModelFirstSample” Step 2:  Add Entity Model item to project 1. Right click on the project & select add new item. 2. In the new item selection menu select “ Data ” then select “ADO.net Entity Model”. 3. Name the item as “ BloggingModel ” 4. Then in the Entity Data Model Wizard select “" Entity Model ” click finish. Step 3:  Create Model Right-click on the design surface and select Properties In the Properties window change the Entity Container Name to BloggingContext Right-click on the design surfac...

Entity Framework Step By Step 1

Image
Thought of writing a series of posts to explain entity framework Step by step so that anyone can easily understand the concepts behind that. This will be the starting point of that. What is Entity Framework? “Entity Framework (EF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write.” As the first step to begin entity frame work the first thing we have to do is to identify which workflow we should adopt. Entity Framework provides 4 different workflows we can adopt for our development based on our requirement.   Which Workflow We should Adopt?   When deciding which workflow we should select there are four question we should answer. 1. Are you targeting new Database , which is empty & tables need to be created? 2. Are you targeting existing Database where tables are already populated? 3. Would you p...