Download presentation
Presentation is loading. Please wait.
1
An Introduction to Entity Framework
By Jai Shrivastav
2
Agenda Life with ADO.Net What is Entity Framework ? Features
Version History Approach EF Core
3
Life with ADO.Net Language C# Sql/MySql
Tools Visual Studio Sql/MySql Server Paradigms Object Procedural Common API ADO.Net
4
Sample ADO.Net Code: using (SqlConnection conn = new SqlConnection("<conn string>")) { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "sp_SomeProc"; “11"); using (SqlDataReader rdr = cmd.ExecuteReader()) while (rdr.read()) string fname = rdr[“FirstName”].toString(); string lname = rdr[“LastNam”].toString(); } We had to do a repetitive work for connecting with database and do the CRUD operations. And since it is loosely typed so no compile time error if wrong parameter name or error in query syntax.
5
What is Entity Framework ?
Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access code that developers usually need to write. In other words we can say that it is bridging the gap between objects and relational data
6
(Business Entities/Domain Classes)
UI Business Layer (Business Entities/Domain Classes) Data Layer Entity Framework Database
7
Features Some features of EF are:
Cross Platform – EF Core is a cross-platform framework which can run on Mac, Linux and Windows. Modeling - EF (Entity Framework) creates an EDM (Entity Data Model) based on POCO (Plain Old CLR Object) entities with get/set properties of different data types
8
Querying - EF allows us to use LINQ queries (C#/VB
Querying - EF allows us to use LINQ queries (C#/VB.NET) to retrieve data from the underlying database. EF also allows us to execute raw SQL queries directly to the database. Change Tracking - EF keeps track of changes occurred to instances of your entities (Property values) which need to be submitted to the database. Saving: EF executes INSERT, UPDATE, and DELETE commands to the database based on the changes occurred to your entities when you call the SaveChanges() method. EF also provides the asynchronous SaveChangesAsync() method. Caching: EF includes first level of caching out of the box. So, repeated querying will return data from the cache instead of hitting the database.
9
Version History EF Version Release Year .Net Framework EF 6 2013
.Net 4.0 & 4.5, VS 2012 EF 5 2012 .Net 4.0 , VS 2012 EF 4.3 2011 EF 4.0 2010 .Net 4.0 , VS 2010 EF 1.0 (or 3.5) 2008 .Net 3.5 SP1, VS 2008 EF Core Version Release Date .Net Framework EF 2.0 Aug 2017 Core 2.0, VS 2017 EF 1.1 Nov 2016 Core 1.1 EF 1.0 June 2016 Core 1.0
10
Approach Entity Framework Code First DB First Model First
11
Code First - This approach was introduced with EF 4. 1
Code First - This approach was introduced with EF 4.1. It is mainly useful in Domain Driven Design. In the Code-First approach, you focus on the domain of your application and start creating classes for your domain entity rather than design your database first and then create the classes which match your database design. The following figure illustrates the code-first approach. Model First - In this approach we define your model in an Entity Framework designer then generate SQL, which will create database schema to match your model and then you execute the SQL to create the schema in your database. The classes that you interact with in your application are automatically generated from the EDMX file. DB First - The Database First Approach provides an alternative to the Code First and Model First approaches to the Entity Data Model. It creates model codes (classes, properties, DbContext etc.) from the database in the project and those classes become the link between the database and controller.
12
EF Core Entity Framework Core is the new version of Entity Framework after EF 6.x. It is open-source, lightweight, extensible and a cross-platform version of Entity Framework data access technology. EF Core is intended to be used with .NET Core applications. However, it can also be used with standard .NET 4.5+ framework based applications. EF Core supports two development approaches 1) Code-First 2) Database-First. EF Core mainly targets the code-first approach and provides little support for the database-first approach because the visual designer or wizard for DB model is not supported as of EF Core 2.0.
13
THANK YOU!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.