Monday, June 15, 2009

LINQ and Entity Framework Posts for 6/8/2009+

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

• Updated 6/15/2009: Missing MSDN Magazine articles about EF in the June issue.

Entity Framework and Entity Data Model (EF/EDM)

• Danny Simmons’ “Antipatterns To Avoid In N-Tier Applications” article in the June 2009 issue of MSDN Magazine begins:

As a member of the Entity Framework team, I frequently talk to customers about building applications that use the Entity Framework. Probably the topic I get asked about more than anything else is designing n-tier applications. In this article, I will try to set a foundation on which you can build for success in this part of your applications. The majority of the article is devoted to design anti-patterns for n-tier, which are usually the most important issues that I find. This is a topic where there are a lot of options and many issues to consider, so it is important to understand the overall space before making decisions for your particular application. In future articles, I will examine n-tier patterns for success and some of the key APIs and issues specific to the Entity Framework, and provide a sneak peak at features coming in the Microsoft .NET Framework 4 that should make n-tier significantly easier.

Topics include:

    • Understanding n-tier
    • Don't distribute your objects!
    • Custom service or RESTful service?
    • Some n-tier anti-patterns


    • Understanding N-tier
    • Anti-Pattern #1: Tight Coupling
    • Anti-Pattern #2: Assuming Static Requirements
    • Anti-Pattern #3: Mishandled Concurrency
    • Anti-Pattern #4: Stateful Services
    • Anti-Pattern #5: Two Tiers Pretending to be Three
    • Anti-Pattern #6: Undervaluing Simplicity

• Jeremy Miller’s Patterns & Practices column, “The Unit Of Work Pattern And Persistence Ignorance,” in MSDN Magazine’s June 2009 issue begins:

In the April 2009 issue of MSDN Magazine ("Persistence Patterns") I presented some common patterns that you will encounter when using some sort of Object/Relational Mapping (O/RM) technology to persist business entity objects. I think it's unlikely that you or your team will be writing your own O/RM tooling from scratch, but these patterns are important to know to effectively use (or even just to choose) existing tooling.

In this article, I would like to continue the discussion of persistence patterns with the Unit of Work design pattern and examine the issues around persistence ignorance. Throughout most of this article, I will be using a generic invoicing system as the example problem domain.


    • The Unit of Work Pattern
    • Using the Unit of Work
    • Persistence Ignorance
    • Can the Business Logic Run Independently of the Database?
    • Can I Design My Domain Model Independently from the Database Model?
    • How Does My Persistence Strategy Affect My Business Logic?
    • More Units of Work

Matthieu Mezil describes a second extension method for to get entities with a composite key in his Entity Framework v2 : How to get only one entity easier with EF4 post of 6/12/2009.

Gil Fink gives Julie Lerman’s book the thumbs-up in his Programming Entity Framework Book Review post of 6/11/2009.

Alex JamesTip 25 – How to Get Entities by key the easy way of 6/11/2009 provides a general-purpose (but not typesafe) method for getting entities by key that uses the GetCSpaceEntityType<T>() extension method I wrote in Tip 13, to get the EntityType for T.”

Jaroslav Kowalski describes two EF extensions (wrapping providers) that plug into the ADO.NET provider interface in his Tracing and Caching for Entity Framework available on MSDN Code Gallery post of 6/11/2009:

    • EFTracingProvider – which adds the ability to log all SQL commands that are executed (similar to LINQ to SQL’s DataContext.Log

    • EFCachingProvider – which adds transparent query results cache to EF

Here’s Jarek’s diagram for his EF wrapping providers:


You can download the source code for the two providers from the Tracing and Caching Provider Wrappers for Entity Framework section of the MSDN Code Gallery.

Jaroslav Kowalski updates the Entity Framework Toolkits & Extensions wiki in his UPDATED WIKI: Home post of 6/11/2009. EdmGen2.exe TPT Inheritance with LINQ to SQL are flagged New!

Matthieu Mezil adds two extension methods, BeginGroupOfUndoActions and EndGroupOfUndoActions, to his first Undo Redo POC version in Entity Framework: Undo Redo v2 of 6/10/2009.

Danny Simmons announces the first release of his new EF DPMud project to the MSDN Code Gallery in his D3: Release 0.0010 post of 6/10/2009. Danny discusses “a few decisions that came up along the way” and then “dig[s] into some specific code areas.”

Lynn Erikson analyzes EFv2’s CodeOnly feature in his Entity Framework ‘Code Only’? If you take the red pill … post of 6/10/2009.

Alex JamesCode Only post of 6/10/2009 begins:

There are currently two ways to get Entity Framework apps up and running, we call these Database First and Model First respectively.

Database First has been with us since .NET 3.5 SP1, and involves reverse engineering an Entity Data Model from an existing database.

Model First is new to Visual Studio 2010/.NET 4.0 and allows you to create an Entity Data Model from scratch and then generate a database and mapping for it.

However many developers view their Code as their model.

Ideally these developers just want to write some Domain classes and without ever touching a designer or a piece of XML be able to use those classes with the Entity Framework.
Basically they want to write ‘Code Only’.

We are pleased to announce that we’ll be shipping a preview of “Code Only” on top of the .NET Framework 4.0 Beta 1 (more on that in the coming days).

Alex goes on to describe how “Code Only” works in EF v2.


Peter Kellner uncovers an Interesting LINQ side affect, Pass in empty List<int> using Contains and Get Where 0 == 1. Hmm in this 6/14/2009 post.

Shahzad’s Multi tier architecture for Linq to Sql post of 6/13/2009 begins:

This resource shows an approach for using Linq to Sql within a multi tier Asp.Net application, and particularly how it can be made to work well with ObjectDataSources. It is here as a discussion piece as well as a usable bit of code.

The key features are a Request-scoped datacontext and entity repository classes which provide easy to use Create, Retrieve, Update and Delete (CRUD) operations implemented with Generics. Also included is a T4 template for auto generation of repositories from a dbml file.

Alvin Ashcraft gives PLINQO a test drive in his Checking Out PLINQO to Generate LINQ to SQL Code with CodeSmith post of 6/10/2009.

Peter Kellner’s 780 Requests Per Second Verses 110, You Really Need to Compile your LINQ to SQL (LINQ2SQL) Queries post of 6/8/2009 begins:

So, I’ve been on kind of a rant lately about how slow LINQ2SQL is if you don’t compile your queries before executing them.  To be fair, if you are doing Windows Forms Programming, WPF or Silverlight it really does not have much impact.  The reason is that a very complex LINQ query may take 50 milliseconds (1/20th of a second).  No big deal if you just have a dozen or so of them to do.  The story changes though if you are using LINQ2SQL in a web environment that has limited CPU resources.  That is, unless you have unlimited money, if it takes more than one web server to handle your load, your throwing away money by using uncompiled LINQ2SQL.

LINQ to Objects, LINQ to XML, et al.

Fryan Valdez shows you how to Combine two sequences using LINQ Zip Operator with .NET 4.0 in this 6/13/2009 post.

OmegaMan’s Linq vs. DataReader; Visual Examples Showing That Linq Does the Same in Less Lines of Code post of 6/10/2009 describes how to handle DbNull values with INullable<T> when using the SqlDataReader.

ADO.NET Data Services (Astoria)

Phani Raju describes how to use the Silverlight toolkit with ADO.NET Data services for Drill-down Charts using Astoria in this 6/10/2009 post.

Phani Raju describes how to use the Silverlight toolkit with ADO.NET Data services for Master-Details with Accordion in this 6/10/2009 post.

Faisal Mohamood’s POCO in the Entity Framework : Part 3 – Change Tracking with POCO post of 6/10/2009 covers:

    • Snapshot based Change Tracking (pure POCO without proxies)
    • Notification based Change Tracking with Proxies
    • Keeping the State Manager in Sync without using Proxies
    • New Overloads for SaveChanges

ASP.NET Dynamic Data (DD)

No significant posts as of 6/14/2009.

Miscellaneous (WPF, WCF, MVC, Silverlight, etc.)

Phani Raju describes how to use the Silverlight toolkit with ADO.NET Data services for Drill-down Charts using Astoria in this 6/10/2009 post. (Repeated from the ADO.NET Data Services (Astoria) section.)

Phani Raju describes how to use the Silverlight toolkit with ADO.NET Data services for Master-Details with Accordion in this 6/10/2009 post. (Repeated from the ADO.NET Data Services (Astoria) section.)

blog comments powered by Disqus