entity framework 4.0

of 21/21
ADO. Net Entity Framework 4.0

Post on 10-May-2015

1.198 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

ADO.NET Entity framework demonstration by Brij Bhusan for Kolkatageeks.com.

TRANSCRIPT

  • 1.ADO. Net Entity Framework 4.0

2.

  • Need of ORM tools
  • EDM Creation and Components of EDM
    • Database First Approach
    • Model First Approach
  • Working with Linq to Entities
  • Using Stored Procedure with EDM
  • CustomizingEntities with T4 Templates
  • Creating & using POCO entities

3.

  • Why do we need ORM Tools?

4.

    • using (SQLConnection conn = new SQLConnection();
    • {
    • conn.Open();
    • SQLCommand cmd = conn.CreateCommand();
    • cmd.CommandText = sp_StoredProc;
    • cmd.parameters.AddWithValue(@City, Dallas);
    • using (SQLDataReader rdr = cmd.ExecuteReader())
    • {
    • while (rdr.read())
    • {
    • string name = rdr.GetString(0);
    • string city = rdr.GetString(1);
    • }
    • }
    • }
    • Powerful, but fragile and time-consuming

Strings!No compiletime check or Intellisense Parameters loosely bound: -- Names, types, number of not checked until runtime Results are loosely typed 5.

  • Objects != Relational Data
    • OO been around for decades; relational databases even longer
    • Bridging the gap between has been time consuming and expensive:
      • Legacy ADO.NET
      • Hand-built DALs
      • 3 rdparty frameworks
    • But, the core problem remains!

Bigger Problem Relational Data Objects 6. So, Now Mapping Code Transform OO to DB We build plumbing to move data back and forth from data store to business objects . Instead of building business functionality , Application Customer.cs Order.cs Database dbo.customer dbo.order 7.

  • Reduce object-relational impedance mismatch
  • In built support of many Microsofts Product
  • Programming Against a Model, Not the Database
  • Client side Data Model
  • Unified Model to query against different Database
  • Model - First Development
  • POCO Support
  • EDM Designer
  • Rapid Development

8.

  • Meta Data
  • EDM design tools
  • Database first design
  • Model first design
  • Code generation (T4)
  • Object Services
  • POCO support
  • Change tracking
  • Relationship management
  • Entity Client
  • Lazy loading
  • N tier application support

9.

  • Bridge between application and data store
  • Provide ability to work with a conceptual view of data rather than the actual database schema
  • NET APIs provided by the Entity Framework use an EDM for every interaction with the data store, whether it is to retrieve or to save data
  • The Entity Framework tools generate classes from this model that enable you to work with objects described by the EDM

10.

  • Demo EDM Creation (Database First approach)

11.

  • EDM Designer Components
    • Scalar Properties
    • Navigation Properties
    • Associations
    • Entity Container, Entity(Entity Sets) and Attributes properties
    • Multiplicity
      • 1 (One)
      • * (Many)
      • 0..1 (Zero or One)

12. 13.

  • EDM Components
    • Conceptual Model
    • Storage Model
    • Mappings

14.

  • The mapping layer sits between the conceptual and store layers
  • Provides the map from the entity properties back to the tables and columns in the data store
  • Enables further customization of the model

15.

  • Demo EDM Creation (Model First approach)

16.

  • Projection Selecting a specific properties or expression in a query.
  • Eager Loading Requesting the related data to be loaded along with the query result.
  • Defferred Loading Delaying the loading of the requesting data along with the query result.
  • Navigating Moving from an entity to its related entity data.

17.

  • Navigations in Queries Related data can loaded, navigated easily with the help of the relationship in EDM. Not require to construct joins.
  • Navigating to an entity reference
  • Filtering and Sorting with an Entity Reference
  • Navigating to the Entity collection
  • Filtering and Sorting with EntityCollections
  • Aggregates with EntityCollections
  • Joining tables
  • Grouping
  • Aggregating andfilteringthe grouped data
  • Loading the related data
    • Eager loading
    • Lazy loading

18.

  • Managing the entity state
  • ObjectContext -ObjectstateEntry (Unchanged, modified, addedd or deleted)
  • EntityObject EntityState The entity state should be in Sync with objectStateEntry state since this entity managed by objectContext.
  • Saving change back to DB- ObjectContext has a single method, saveChanges, which persists back to the database all of the changes made to the entities.
  • Adding, Updating and Deleting an Entity

19.

  • Stored Procedures returning data can be linked to entities, Scalar Values or Complex types
  • Mapping Insert,Update and Delete functions.
  • Mapping Read Stored Procedures
    • To Entity
    • To Scalar
    • To Complex Types

20.

  • POCO : Plain old CLR Objects
  • Provides the ability to add custom classes in EDM
  • Demo

21.

  • Thank you