Your SlideShare is downloading. ×
0
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Entity Framework -  Object Services
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Entity Framework - Object Services

4,733

Published on

Entity Framework 4.1 - Object Services

Entity Framework 4.1 - Object Services

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,733
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. EF Object Services
    Eyal Vardi
    CEO E4D Solutions LTDMicrosoft MVP Visual C#blog: www.eVardi.com
  • 2. Agenda
    EF Architecture
    Development Approaches
    Entity Data Model (EDM)
    Object Services
    Querying & Loading Entities
    EDM
    LINQ to Entities
    Entity SQL
    Conceptual Model
    Object Services
    Mapping
    Entity Client Provider
    StorageModel
    ADO.NET Provider
  • 3. Services:- Change tracking- Concurrency control- Object identity
    SQL or Stored Procs
    Rows
    SQLServer
    Entity Framework
    EF Architecture
    Application
    from c in db.Customerswhere c.City == "London"select new { c.Name, c.Phone }
    Objects
    LINQ Query
    SubmitChanges()
    EDMX
    ADO.NET Provider
    SQL Query
    select Name, Phonefrom customerswhere city = 'London'
  • 4. EF Architecture
    SQLServer
    EDM
    LINQ to Entities
    Entity SQL
    Conceptual Model
    Object Services
    Mapping
    Entity Client Provider
    StorageModel
    ADO.NET Provider
  • 5. Object Services
    Materialization
    The process of transforming the data obtained from the Entity Client data provider, which has a tabular structure, into objects.
    Change tracking
    Tracks any changes made to the objects.
    Query transformation
    Translates queries it into a command tree that’s then passed on to the underlying Entity Client.
    • Object identities
  • Object Services Functions
    Querying
    Querying data as objects
    Shaping query results
    Composing queries
    CRUD
    Lazy loading
    Inheritance
    Navigating relationship
    Change tracking
    Saving changes
    Attaching objects
    Detaching objects
    Serializing objects
    Managing
    Object identities
    Concurrency
    Transactions
  • 6. LINQ to Entities (Finding)
    DbSet and IDbSet implement IQueryable.
    DbSetand IDbSet always create queries against the database
    always involve a round trip to the database even if the entities returned already exist in the context.
  • 7. Finding an Entity by Primary Key
    Look on the context
    A round-trip to the database will only be made if the entity with the given key is not found in the context.
  • 8. Eagerly Loading
    Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query.
  • 9. Eagerly Loading (multiple levels)
    It is also possible to eagerly load multiple levels of related entities.
  • 10. Lazy Loading
    POCO Properties Must be Virtual.
    Configuration.LazyLoadingEnabled = true;
  • 11. Explicitly Loading
    Even with lazy loading disabled it is still possible to lazily load related entities, but it must be done with an explicit call.
  • 12. Explicitly Loading
  • 13. Count Related Entities Without Loading Them
  • 14. Local Data
    The Local property of DbSetprovides simple access to the entities of the set that are currently being tracked by the context and have not been marked as Deleted.
    Accessing the Local property never causes a query to be sent to the database.
  • 15. No Tracking Queries
    Sometimes you may want to get entities back from a query but not have those entities be tracked by the context.
    Better performance
    Read-only scenarios
  • 16. Entity States & Save Changes
    Entity states before & After Save Changes.
  • 17. Adding a New Entity to the Context
  • 18. Adding a New Entity to the Context
    Add a new entity to the context by hooking it up to another entity that is already being tracked.
  • 19. Attaching an Existing Entity to the Context
    Entity that already exists in the database but which is not currently being tracked by the context then you can tell the context to track the entity using the Attach method on DbSet.
  • 20. Original & Current Values
  • 21. Marking a Property as Modified
    Marking a property as modified forces an update to be send to the database for the property when SaveChanges is called even if the current value of the property is the same as its original value.
  • 22.
  • 23. Current values: Property Id has value 1 Property Name has value FrankyProperty Version has value System.Byte[] Property PrincessId has value 1
    Original values: Property Id has value 1 Property Name has value BinkyProperty Version has value System.Byte[] Property PrincessId has value 1
    Database values: Property Id has value 1 Property Name has value Squeaky Property Version has value System.Byte[] Property PrincessId has value 1
  • 24. Setting Values From Another Object
    Current values: Property Id has value 1 Property Name has value Rapunzel
    Original values: Property Id has value 1 Property Name has value Rosannella
  • 25. Getting & Setting Complex Pro’s
  • 26. Dynamic Proxies
    When creating instances of POCO entity types, the EF often creates instances of a dynamically generated derived type that acts as a proxy for the entity.
    This proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed.Configuration.ProxyCreationEnabled = true;
  • 27. Creating an Instance of a Proxy
    The Create method does not add or attach the created entity to the context.
    If the entity type is sealed and/or has no virtual properties then Create will just create an instance of the entity type.
  • 28. Automatically Detecting Changes
    DbContext automatically detecting changes when the following methods are called:
    DbSet.Find
    DbSet.Local
    DbSet.Remove
    DbSet.Add
    DbSet.Attach
    DbContext.SaveChanges
    DbContext.GetValidationErrors
    DbContext.EntryDbChangeTracker.Entries
  • 29. Disabling Auto Detecting Changes
    performance improvements
    An alternative to disabling and re-enabling is to leave automatic detection of changes turned off at all times and either call context.ChangeTracker.DetectChangesexplicitly.

×