Wednesday, July 01, 2009

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

Updated 7/1/2009: Damien Guard’s LINQ to SQL article of 6/24/2009
• Updated 6/28/2009: Huagati LINQ to SQL Profiler, LINQ to SQL in Mono, other additions

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

Entity Framework and Entity Data Model (EF/EDM)

Danny Simmons continues his DPMud series with the second release and the D3: Fun with Concurrency and Model First – Part 1 and D3: Fun with Concurrency and Model First – Part 2 posts of 6/27/2009:

[The task is] to add a concurrency-token property to each of my entities and a simple test to verify that optimistic concurrency checks are working correctly.  Seems pretty simple right?  The model currently only has 4 entities, so how hard could it be?  Can you say “working all week on this one task”?  :-(

Dot Net RulesBuilding an ASP.Net application with C# and Entity Framework post of 6/27/2009 offers a detailed, illustrated introduction to using EF v1 as a data layer for ASP.NET 3.5 projects.

Lynn Eriksen discovers It was the EF providers. EntityDataSource off the hook in this 6/27/2009 post:

The title says it all. It was the EF providers I was looking at that cause my issues when using ‘OrderBy’, ‘Skip’ and ‘Take’ together. It all has to do with how the expression trees are created when using ‘Take’. Let’s look at the two scenarios. …

Wade Wegner’s Architecting Your Data Access Layer with the Entity Framework post of 6/26/2009 begins:

I think we can all agree – and if not, please let me know why – that the Entity Framework provides some awesome capabilities – mapping your conceptual schema to your data schema, isolation from the relational database and database schema, change tracking and identity resolution, full query comprehension and optimization, and more.  Yet, despite these features, it is difficult to figure out how and where to include the Entity Framework in your application architecture.

And goes on to describe a recent presentation with one of his fellow evangelists, Dave Bost:

In preparation for this talk, I spent a lot of time looking at different strategies and architectures for using your data access layer (DAL) and the Entity Framework – or any O/RM tool, for that matter.  In the end, I settled on three approaches – certainly there are other patterns and approaches, but I found these to be the most relevant:

  1. Entity Framework as the DAL
  2. Full encapsulation of the Entity Framework
  3. Partial encapsulation of the Entity Framework

Wade concludes with the slide deck he used for the presentation.

Matthieu Mezil creates an interface for a T4 POCO template in his POCO T4 post of 6/26/2009:

With EF4 features CTP1, we have a great POCO template which is divided in two tt files to allow us to have the entitiy POCO classes and the context in different projects.

It’s very very cool.

However, I think that it’s a shame not to have an interface for the context particularly to mock it.

So he shows you how change the file to create an interface for the context.

Julie Lerman’s Effective EF with Oracle post of 6/26/2009 covers DataDirect’s Oracle data provider with EF support:

Now that DataDirect’s Beta of their Oracle Provider with EF support is available, Jonathan Bruce (from DD) is starting to write technical posts about how to use it.

Yesterday he posted Effective EF with Oracle

And today: Effective EF with Oracle (Stored Procedures with REF CURSORs)

Pablo M. Cibraro (a.k.a. Cibrax) calls out A Bad Idea, EF Entities over WCF in this 6/25/2009 post:

Do you want to see something very ugly?. Try to send a complete EF [v1] entity directly as a data contract over the wire with WCF.


•• Damien Guard describes problems with Client-side properties and any remote LINQ provider because:

[T]hese properties can’t be translated and sent to the server as they have been compiled into intermediate language (IL) and not LINQ expression trees that are required for translation by IQueryable implementations. …

The solution in his 6/24/2009 post:

What we came up (David [Fowler], Colin Meek and myself) is a provider-independent way of declaring properties just once so they can be used in both scenarios. Computed properties for LINQ to SQL, LINQ to Entities and anything else LINQ enabled with little effort and it works great on .NET 3.5 SP1 :)

Thanks to Damien for the heads up via Twitter.

Kristofer Andersson’s Profiling Linq-to-SQL applications detailed post of 6/24/2009 explains why “runtime profiling live production systems [with the Huagati LINQ to SQL Profiler] can sometimes reveal bottlenecks and/or room for improvements/optimization that would not show up during development/test/QA, or on dev/test systems” [see below.]

• Huagati Systems announces the availability on 6/20/2009, v1.11 of the Huagati LINQ to SQL Profiler, which consists of two components:

  1. A royalty-free redistributable runtime extension library that adds query profiling functionality to Linq-to-SQL datacontexts. Basic profiling requires only two added method calls to existing code; BeginProfiling and EndProfiling, while more advanced options with pre-defined filters and custom filters are available for more complex profiling tasks.
  2. A non-redistributable profiler log viewer that allows developers, DBAs, product/program managers, and system administrators to browse the profiler logs, identify expensive queries, view the managed call stack that generated the query, see vital SQL Server I/O and timing statistics from the actual execution of the query etc.

You can download v1.11 from here and receive a 45-day trial license here.

Miguel de Icaza reports by Twitter on 6/28/2009: “Mono trunk now has LINQ to SQL, we will likely backport to 2.4 and will be in 2.6. These people of no faith.”

LINQ to SQL continues to live. Good news!

Naspinski reports he has posted his IQueryableSearch class to CodePlex in his IQueryableSearch is now up on CodePlex post of of 6/26/2009. He has described the class in this Universal IQueryable Search Usable by Linq-to-SQL and Linq-to-Entities post of 5/10/2009.

John Opincar compares Stored Procedures Versus LINQ to SQL for Dynamic WHERE Clauses in his detailed post of 6/23/2009:

I was recently discussing the best way to solve the “bad plan gets cached for super-complex WHERE clause with a large number of @column IS NULL OR T.Column = @column conjuncts” problem with colleagues at work. This is another variant of the age-old “stored procedures versus code-generated SQL” (including ORMs here) debate.

LINQ to Objects, LINQ to XML, et al.

Jim Wooley reports LINQ in Action XML samples added to LINQPad in this 6/28/2009 post:

The beginning of this month, we released the samples from LINQ in Action for chapters 1-8 which covers LINQ to Objects, LINQ to SQL, and the new Language features. We're happy to announce that the next three chapters covering LINQ to XML are now available. That's over 70 new samples in VB and C# each. Follow the directions on the original announcement to download and use these samples.

Jeff Craig’s Inclusively Take Elements using LINQ and Custom Extensions post of 6/26/2009 takes on this problem:

I ran into an interesting LINQ problem recently, one which required me to extend LINQ in my own fashion. The problem was fairly simple. I’m trying to build a list of every day a course meets over the course of a term. I start by querying our Academic Calendar for every event in the calendar, then I skip all the events prior to the first day of class, taking all the events until the end of classes for the term. I couldn’t just take those two events, because different events in the middle of the term affect if courses are offered.

Jim Wooley offers his itinerary of “speaking engagements” (presumably about LINQ) throughout the southeast in this 6/25/2009 post:

Frans Bouma warns Linq: Beware of the 'Access to modified closure' demon in this 6/25/2009 post:

If you're using Linq and Resharper, you've probably seen the warning Resharper shows when you use a foreach loop in which you use the loop variable in a Linq extension method (be it on IQueryable<T> or IEnumerable<T>). In case you don't know what it is or what damage it can do if you ignore the issue, I'll give you a database oriented query (so on IQueryable<T>, using LLBLGen Pro's Linq provider) which creates a dynamic Where clause based on input, the typical scenario you should be careful with when it comes to this particular problem.

ADO.NET Data Services (Astoria)

Stay tuned for Sunday’s updates.

ASP.NET Dynamic Data (DD)

Stay tuned for Sunday’s updates. 

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

David Ebbo’s The MVC T4 template is now up on CodePlex, and it does change your code a bit post of 6/26/2009 reports:

The MVC T4 template (now named T4MVC) is now available on CodePlex, as one of the downloads in the ASP.NET MVC v1.0 Source page.

and proves his addition to T4-based code generation for MVC projects. His earlier Mind if my MVC T4 template changes your code a bit? post of 6/24/2009 begins:

When working on my MVC T4 template, I was not able to use reflection to discover the Controllers and Actions, because the code that the template generates is itself in the same assembly as the controllers.  So that causes a bit of a chicken and egg problem.

Instead, I had to get out of my element and learn something I was not familiar with: the Visual Studio File Code Model API.  It’s very different from using reflection, because instead of working at the assembly level, you work at the source file level.

and A T4 based approach to creating ASP.NET MVC strongly typed helpers starts with:

Earlier this week, I wrote a post on using a BuildProvider to create ActionLink helpers.  That approach was using CodeDom to generate the code, and there was quite some user interest in it (and Phil blogged it, which helped!).

Then yesterday, I wrote a post on the Pros and Cons of using CodeDom vs T4 templates for source code generation.  They are drastically different approaches, and while both have their strengths, T4 has definitely been getting more buzz lately.

The logical follow-up to those two posts is a discussion on using T4 templates to generate MVC strongly typed helpers.  The general idea here is to use the existing ASP.NET extensibility points (BuildProvider and ControlBuilder), but rely on T4 templates to produce code instead of CodeDom.  Hence, I called the helper library AspNetT4Bridge (I’m really good at naming things!).

As far as I know, this is the first time that T4 templates are executed dynamically inside an ASP.NET application, so let’s view this as an experiment, which has really not been put to the test yet.  But it is certainly an exciting approach, so let’s see where it takes us!

blog comments powered by Disqus