Saturday, October 10, 2009

LINQ and Entity Framework Posts for 10/5/2009+

Note: This post is updated weekly or more frequently, depending on the availability of new articles.

Entity Framework and Entity Data Model (EF/EDM)

Alex James announces in a 10/6/2009 post that the EF team is Extending the Entity Framework Provider Model to support DDL:

As part of the first previews of Code-Only we shared some code to create a database:

// Create a context using code-only
using (var mycontext = builder.Create(dbConnection))
    // Create the database if it doesn’t already exist
    if (!myContext.DatabaseExists())
    // Standard EF code goes here.

But in the first preview of Code-Only this code only worked against SQL Server.

The problem is that our public Provider Model (i.e. DbProviderServices) has no Database Definition Language or DDL features.

Provider Model Changes

To support DDL features across different databases, we plan to extend DbProviderServices, with DDL specific services.

These services will be accessed through these public methods:

public string CreateDatabaseScript(
   string providerManifestToken,
   StoreItemCollection storeItemCollection);

public void CreateDatabase(
   DbConnection connection,
   int? commandTimeout,
   StoreItemCollection storeItemCollection);

public bool DatabaseExists(
   DbConnection connection,
   int? commandTimeout,
   StoreItemCollection storeItemCollection);

public void DeleteDatabase(
   DbConnection connection,
   int? commandTimeout,
   StoreItemCollection storeItemCollection);

Now internally those methods will call through to … ‘protected virtual’ methods which will do the actual work.

Matthieu Mezil’s EF: Include with where clause post of 10/6/2009 claims the following:

Several guys ask me if it’s possible to add a condition in the Include method and the answer is no.

However you can do an equivalent like this:

from cWithP in

    (from c in context.Categories

select new


         Category = c,

         Products = from p in c.Products

where p.UnitPrice > 20

select p


select cWithP.Category;

or the condensed equivalent:

context.Categories.Select(c => new { Category = c, Products = c.Products.Where(p => p.UnitPrice > 20) }).AsEnumerable().Select(cp => cp.Category);


Syed Mehroz Alam’s LINQ to SQL: Visual Studio designer failed to autogenerate .designer.cs data classes post of 10/5/2009 recounts:

I had a really strange observation today. I opened one of my LINQ to SQL dbml files, made some changes, and then saved it back to have my designer generated data classes updated. But instead of reflecting my changes in the .designer.cs class, Visual studio deleted that designer generated file. I tried several times but every time LINQ designer was deleting my autogenerated data classes. I googled and found an amazing answer by Marc Gravell at this stackoverflow question. The position of using statements was the source of problem!!! I had extended the LINQ generated partial classes and the first statement in that file was “using System”. I removed that and the VS designer was happy again.

So for anyone else that experiences the same problem, try moving your using statements after the namespace declaration.

Scott Guthrie sent the following retweet on 10/10/2009:

r @junglesoft LINQ to SQL is fully supported in VS10/.NET 4.0. Here is a list of improvements in it: …

which received numerous retweets itself. The expanded URL points to Damien Guard’s LINQ to SQL changes in .NET 4.0 post of 6/1/2009 (updated 8/25/2009).

LINQ to Objects, LINQ to XML, et al.

Fredrik ErasmusLinq to XML and DataSet to XML post of 10/7/2009 follows his Growing into Learning LINQ to XML post of 10/5/2009 and begins:

On Monday I started working through some LINQ to XML and it got me so excited that I misunderstood some project requirements that ended up being quite wrong. It did not, however, diminish my enthusiasm. I ended up using a small part of the code in the end anyway, even though it was not in a production environment.

Lets say you have a collection of XML documents and you would like to know what elements appear in all of them, so at the end of it all you have a single of list of elements that appear between all of them.

Fredrik continues with the code to accomplish his objective and then shows how to return the raw XML document of a dataset.

ADO.NET Data Services (Astoria)

No significant new posts this week.

ASP.NET Dynamic Data (DD)

Gil Fink’s Create Your First Dynamic Data Entities Web Application post of 10/6/2009 opens with:

Two weeks ago I was asked if there is a way to build a web back office quickly. One thing that popped into my mind was the new ASP.NET Dynamic Data framework that was shipped with Visual Studio 2008 SP1. This post is the same introduction that I made to the team members that asked me the question. Since there weren’t any customizations needed in the back office they needed the result was a standing back office in 5 minutes. That is very productive.

Gil continues with a detailed tutorial for a basic ASP.NET Dynamic Data project.


blog comments powered by Disqus