ADO.NET Entity Framework

I attended a Microsoft presentation last night on the new ADO.NET Entity Framework which was released on Monday (11 Aug 08) as part of VS 2008 SP1 and .NET Framework 3.5 SP1.

The essential idea is to allow developers to use LINQ to work against a conceptual model of the database instead of the physical model.

The Entity Framework uses two XML mappings

SSDL - Store Schema Definition Language (the physical schema)
CSDL - Conceptual Schema Definition Language (the coneptual model)

There is a nice graphical tool to allow you to manage the conceptual model and a wizard to bring in the existing physical model.

The tool not only allows you to map a different schema (tables, data types, column names etc) but to actually add rules, so for example if a column holds a certain value then map to a different table.

Example - you have a multi-use table that has 100 columns, but no row actually makes use of all the columns, different columns get used in different situations. For the conceptual model you could create tables for each situation so the properties you are looking at in the code all make sense for the current object, you don't have a lot of redundant properties. These rules include Object Relational Mapping Capabilities, which supports derived types. This is because with the Entity Framework you are writing something called Entity SQL, which includes extra capabilities such as inheritance.

There were a couple of useful details I picked up on LINQ too.

Tables with foreign keys have what are called "navigation items" which are links to related objects. So for example a customer object might have an Orders navigation item - the orders for that customer.

However if you load a customer with LINQ and then start querying the orders, you won't get anything (for example if you do cust.Orders.Count() it will return zero). This is beacuse you need to explicity tell LINQ which nagivation items you want to work with, otherwise there will be no data loaded.

The other point was the SQL generated by LINQ isn't always what you expect. The presenter asked for entries that started with "U" in LINQ) and the SQL generated used charindex(..) whereas I would have thought LIKE would have been more efficient, there were a couple of other examples like that too.

One final point the presenter made was that Microsoft appear to now have some duplication of database technologies with the Entity Framework and LINQ to SQL and he expected them to be rationalised into a single model at some point in the future, which points to potentially significant changes in this technology in future releases.

Here is the wiki article on the Entity Framework

http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework

Here are some links he shared (the first one is his blog - search on "Entity" for related articles)

http://mtaulty.com/communityserver/blogs/mike_taultys_blog/default.aspx

http://www.datadeveloper.net/

http://blogs.msdn.com/adonet/