Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Entity Framework - Various Models to Query, Various Means to Querying

Blogs

Mike Taulty's Blog

Elsewhere

I'm still watching this URL ;-) and waiting for new Entity Framework bits to be released but, in the meantime, I've been trying to draw a picture of all the flexibility that ADO.NET V3.0 and the Entity Framework brings to us as developers in terms of what we can query and how we go about querying it.

I may not have this quite right but the way I view it is that with all the bits in ADO.NET V3.0 we have a layered approach something like this;

image

So, what is that diagram trying to say?

Starting with the blue box at the bottom;

  1. Today, we have our database such as SQL Server (I'm using that as a concrete example here).
  2. It has schema that consist of tables, views, stored procedures, functions, etc.
  3. The database comes with a specific ADO.NET provider which provides classes (SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter) that allow us to execute commands using store specific language (T-SQL) in order to get result-sets.
  4. The Entity Framework introduces a modelling language for this store called Store Schema Definition Language which allows us to build a model of the store. That model is sometimes termed S-Space.

Moving on to the green box at the top;

  1. Tomorrow, we can define a conceptual model that we want to write queries against.
  2. It has a schema that consists of Containers, EntitySets, AssociationSets (where an EntitySet contains entities of an EntityType (or derived types) and an AssociationSet contains associations of an AssociationType and so on).
  3. The conceptual model comes with a generic ADO.NET provider which provides classes (EntityConnection, EntityCommand, EntityDataReader) that allow us to query the model using commands written in a store neutral language in order to get result-sets.
  4. The Entity Framework introduces a modelling language for this model called Conceptual Schema Definition Language. This model is sometimes termed C-Space.
  5. The Entity Framework introduces a mapping language for flexibly mapping the C-Space to the S-Space and it calls this Mapping Schema Language or MSL.

Adding in another picture above the first one because it doesn't stop there (notice, the bottom half of this picture is the same as the top half of the first picture);

image

What does this picture add?

Looking at the red box at the top;

  1. Tomorrow, we can define an object model that we want to write queries against.
  2. It has a "schema" that consists of Types, Properties, Methods, Collections and so on.
  3. The object model comes with classes that can query against it using Entity SQL. Those classes are the ObjectContext and the ObjectQuery<T> and they work together to provide rich object-oriented services for querying and updating data.
  4. This object model is sometimes referred to as O-Space and is defined purely in terms of .NET types with a 1:1 mapping between those types and the C-Space.
  5. The mapping between O-Space and C-Space is currently defined by .NET attributes that are used to attribute to the object model.
  6. The ObjectQuery<T> type is fully LINQ enabled allowing developers to allow developers to (where sensible) avoid constructing Entity SQL and define queries purely using their favourite language syntax.

So, with Entity Framework and ADO.NET V3.0 we get an awful lot of flexibility;

  1. Write queries at the traditional Store level - i.e. stay where you are :-)
  2. Write queries at the Conceptual level using Entity SQL - i.e. benefit from abstracting the language of the store, abstracting the schema of the store and move to a richer model for querying (supporting inheritance, relationships, etc).
  3. Write queries at the Object level using Entity SQL - i.e. benefit from dealing with queries that return collections of objects rather than tabular data that we'd find in a IDataReader and performing inserts, updates, deletes against the object model rather than by executing store commands.
  4. Write queries at the Object level using LINQ - i.e. as (3) but benefit from constructing queries using strongly typed objects rather constructing Entity SQL.
  5. Some combination of (3) and (4) (and, hey, throw in a bit of (2) if you like) where appropriate.

It seems to me that it's going to be an exciting time (this is what I call understatement :-)).


Posted Tue, Aug 21 2007 4:47 PM by mtaulty

Comments

TrackBack wrote
on Wed, Aug 22 2007 11:11 AM
Jason Haley wrote Interesting Finds: August 22, 2007
on Thu, Aug 23 2007 7:13 AM
Mike Taulty's Blog wrote ADO.NET Entity Framework - Bringing Together A Few Previous Posts
on Wed, Aug 29 2007 5:39 PM
This is just a convenience - links to the posts that I've made so far around beta 2 of the ADO.NET Entity...
Entity Framework from Mike Taulty « vincenthome’s Software Development wrote Entity Framework from Mike Taulty &laquo; vincenthome&#8217;s Software Development
on Fri, Sep 7 2007 7:26 AM