Published
Tuesday, August 21, 2007 4:47 PM
by
mtaulty
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;
So, what is that diagram trying to say?
Starting with the blue box at the bottom;
- Today, we have our database such as SQL Server (I'm using that as a concrete example here).
- It has schema that consist of tables, views, stored procedures, functions, etc.
- 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.
- 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;
- Tomorrow, we can define a conceptual model that we want to write queries against.
- 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).
- 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.
- The Entity Framework introduces a modelling language for this model called Conceptual Schema Definition Language. This model is sometimes termed C-Space.
- 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);
What does this picture add?
Looking at the red box at the top;
- Tomorrow, we can define an object model that we want to write queries against.
- It has a "schema" that consists of Types, Properties, Methods, Collections and so on.
- 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.
- 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.
- The mapping between O-Space and C-Space is currently defined by .NET attributes that are used to attribute to the object model.
- 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;
- Write queries at the traditional Store level - i.e. stay where you are :-)
- 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).
- 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.
- 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.
- 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 :-)).