DataAccess using ADO.NET

download DataAccess using ADO.NET

of 27

Transcript of DataAccess using ADO.NET

  • 8/9/2019 DataAccess using ADO.NET

    1/27

    Data Access with

    ADO.NET 3.5

    Claeys Kurt

    www.devitect.net

    26/03/09

  • 8/9/2019 DataAccess using ADO.NET

    2/27

    LINQ as query language LINQ to SQL

    LINQ to Entities (=ADO.NET Entity Framework)

    ENTITY SQL

    ADO.NET DataServices

    ASP.NET Dynamic Data

    ADO.NET 3.5

  • 8/9/2019 DataAccess using ADO.NET

    3/27

    Overview

    LINQ Enabled Datasources

    LINQ Enabled ADO.NET

    Objects

    XMLRelational

    C# VB ....NET Language-Integrated Query (LINQ)

    LINQ to

    Objects

    LINQ to

    DataSet

    LINQ to

    SQL

    LINQ to

    Entities

    LINQ to

    XML

  • 8/9/2019 DataAccess using ADO.NET

    4/27

    LINQ as Query Language

    from idin source

    { from idin source |

    join idin source on exprequals expr[ into id] |

    let id= expr|

    where condition |

    orderby ordering, ordering, }

    select expr| group exprby key

    [ into id query]

    Starts withfrom

    Zero or morefrom,join, let, where, ororderby

    Ends withselector group by

    Optional intocontinuation

  • 8/9/2019 DataAccess using ADO.NET

    5/27

    var contacts =from c in customers

    where c.State == "WA"select new { c.Name, c.Phone };

    var contacts =customers.Where(c => c.State == "WA").Select(c => new { c.Name, c.Phone });

    Extension

    methods

    Lambda

    expressions

    Query

    expressions

    Object

    initializers

    Anonymous

    types

    Local variable

    type inference

    LINQ as Query Language

  • 8/9/2019 DataAccess using ADO.NET

    6/27

    Query Expressions

    Project Select Filter Where , Distinct

    Test Any(), All()

    Join Join On Equals

    Group Group By , Into ,

    Group Join On Equals Into

    Aggregate Count(), Sum(), Min(), Max(),Avg()

    Partition Skip [ While ] , Take [ While ] Set Union, Intersect, Except

    Order Order By , [ Ascending | Descending ]

  • 8/9/2019 DataAccess using ADO.NET

    7/27

    LINQ Architecture

    System.Linq.EnumerableDelegate based

    Source implements

    IEnumerable

    var query = from c in customers where c.City == "Hove" select c.Name;

    var query = customers.Where(c => c.City == "Hove").Select(c => c.Name);

    System.Linq.QueryableExpression tree based

    Source implements

    IQueryable

    SQL DataSetsCollection of

    objects inmemory

    Others

  • 8/9/2019 DataAccess using ADO.NET

    8/27

    OR Mapping

    Data Objects !

  • 8/9/2019 DataAccess using ADO.NET

    9/27

    Store

    Application

    Collection of Objects

    OR Mapper

    LINQ Query

    T-SQL Query

    SQL Tabular Data

    Collection in memory

    Tables

    OR Mapping

  • 8/9/2019 DataAccess using ADO.NET

    10/27

    Level ofAbstraction

    Low-level:databaseschema

    Higher-level:

    conceptualschema

    QueryLanguage

    Query inquotes

    Language-

    IntegratedQuery (LINQ)

    QueryResults

    Loosely-typed(brittle, error-

    prone)

    Strongly-typed

    ADO.NET 2.0

    ADO.NET 3.5

    Data Access Evolution

  • 8/9/2019 DataAccess using ADO.NET

    11/27

    Demo on LINQ to SQL

  • 8/9/2019 DataAccess using ADO.NET

    12/27

    Entity Framework

    Schema independence

    Store independence

    Higher level constructs Relationships

    Inheritance

    Composite Entities

    Conceptual Model

    .NET Provider

    (EntitySQL)

    ORM & LINQ

    V3.0

    Store

    M

    apping

  • 8/9/2019 DataAccess using ADO.NET

    13/27

    Entity Framework

    .NET Entity Provider (Entity SQL)

    Command

    ConnectionReader

    EF

    Store.NET Data Provider

    V2.0

    Command

    ConnectionReader

    Adapter

    EF

    Conceptual Model

    Entity Entity

    relationship

    Mapping (MSL)

    EF Programming Model

    Updating through the ObjectContext

    Quering with LINQ or Entity SQL

  • 8/9/2019 DataAccess using ADO.NET

    14/27

    O/R Mapping

    MappingConceptual MappingLogical

    *

    *

  • 8/9/2019 DataAccess using ADO.NET

    15/27

    3 Layers

    The logical store model that represents the relational schema from a database.

    Logical layer (SSDL)

    The mapping between CSDL and SSDL.

    Mapping layer(MSL)

    The conceptual entity model that represents the entities and their associations and

    inheritance structure.

    Conceptual layer(CSDL)

  • 8/9/2019 DataAccess using ADO.NET

    16/27

    TPC MappingFowler : Concrete Table Inheritance

    Microsoft : Table Per Concrete Type (TPC)Represents an inheritance hierarchy of classes with one

    table per concrete class in the hierarchy

  • 8/9/2019 DataAccess using ADO.NET

    17/27

    TPT MappingFowler : Class Table Inheritance

    Microsoft : Table Per Type (TPT)Represents an inheritance hierarchy of classes with one

    table for each class

  • 8/9/2019 DataAccess using ADO.NET

    18/27

    TPH MappingFowler : Single Table Inheritance

    Microsoft : Table Per Hierarchy (TPH)

    Represents an inheritance hierarchy of classes as a single table

    that has columns for all the fields of the various classes.

  • 8/9/2019 DataAccess using ADO.NET

    19/27

    The Role of the ObjectContext

    ObjectContext

    DatabaseTables

    Attach

    1. Query

    Notifies

    2. Update the Entities

    ChangeTracking

    3. Save Changes

  • 8/9/2019 DataAccess using ADO.NET

    20/27

    Demo on Entity Framework

    i

  • 8/9/2019 DataAccess using ADO.NET

    21/27

    Project Astoria, ASP.NET extensions

    Exposing data (CRUD)

    Needs conceptual model (L2S or EF)

    Lightweight HTTP based access (no soap)

    Supports URI translation

    Atom/JSON wire formats

    IQueryable interface IUpdatable interface

    System.Data.Services namespace

    ADO.NET DataServices

    RESTFul !

    RESTF l ?

  • 8/9/2019 DataAccess using ADO.NET

    22/27

    Resources

    Res 1

    Res 2

    Res 3

    Res 4

    HTTP Request

    URL

    VERB

    Payload

    HTTP Response

    Status

    GET

    POST

    PUTDELETEXML JSON

    Payload

    XML JSON

    RESTFul ?

  • 8/9/2019 DataAccess using ADO.NET

    23/27

    Demo on ADO.NET DataServices

    ASP NET D i D

  • 8/9/2019 DataAccess using ADO.NET

    24/27

    Create a webapp to maintain a database with

    no coding !

    UI based on templates

    Needs conceptual model (L2S or EF)

    HTTP based access

    ASP.NET Dynamic Data

    ASP NET D i D t

  • 8/9/2019 DataAccess using ADO.NET

    25/27

    Uses DynamicData Controls to build editable

    screens.

    Builds in Paging, Sorting, Filtering, and

    Validation automatically.

    Dynamic Data fields for rendering individual

    data types.

    Allows a great deal of customization.

    ASP.NET Dynamic Data

    ASP NET D i D t

  • 8/9/2019 DataAccess using ADO.NET

    26/27

    ASP.NET Dynamic Data

  • 8/9/2019 DataAccess using ADO.NET

    27/27

    Demo on ASP.NET Dynamic Data