LINQ and Entity Framework Posts for 10/12/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 continues his Entity Framework Tips series with Tip 38 – How to use CodeOnly with Astoria of 10/14/2009:
The normal way that you create an ADO.NET Data Services (aka Astoria) Service is by creating a class that derives from DataService<T>.
public class BloggingService : DataService<BloggingEntities>
And if you want to use Entity Framework under the hood the T you supply must derive from ObjectContext.
Under the hood the DataService constructs an instance of the BloggingEntities, and gets the model from it, via its MetadataWorkspace.
The problem is if you’ve configured the model using Code-Only, the only way to construct the BloggingEntities is via the Code-Only ContextBuilder, which Astoria knows nothing about.
Hmm….
Thankfully there is a very simple workaround, you simply override CreateDataSource() on DataService<T>.
Alex then shows you how.
Sam Gentile describes in his Focusing on Data – Try #3 post of 10/13/2009 how he came to the conclusion that he needed to understand SQL:
As I begun to spin up with a lot of Microsoft’s new generation of technologies like LINQ, LINQ to SQL, Astoria, and the Entity Framework, it became apparent that this couldn’t stand anymore. I had coded .NET the last few years without really embracing LINQ and similar technologies. As I begun to dig into LINQ (especially LINQ to SQL) and then tried to digest Julie Lerman’s fabulous and definitive Programming Entity Framework, I started to really feel that I had to understand SQL. When Julie’s book sailed over my head, I realized there were two issues here: LINQ itself and SQL. I wasn’t even digesting LINQ queries. This led me to two things. The first is Pluralsight’s On Demand course for LINQ taught by K. Scott Allan, and then Murach’s ADO.NET 3.5: LINQ and the Entity Framework with C# 2008. That helped quite a bit with LINQ, LINQ to SQL and Entity Framework
Alex James’ Code-Only best practices post of 10/13/2009 begins:
There have been lots of posts on the EFDesign blog talking about how the features in Code Only have evolved.
But very little covering what we think will be the best way to write the code.
And then shows you how to write the code.
Gil Fink tackles Table Splitting in Entity Framework in the 10/12/2009 post:
Entity Framework include a lot of ways to customize the Entity Data Model. One such way is Table Splitting which enables to map multiple entity types to a single table. This post will show how we can achieve this ability. [Emphasis Gil’s.]
Alex James describes Code Only – Further Enhancements in this detailed 10/12/2009 tutorial:
We’ve come a long way since the last post on Code-Only. So it’s high time for another update.
We’ve been working really hard on Code-Only revving the design, and spotting missing capabilities and responding to feedback both internal and external etc.
The current plan still holds. Code-Only will not be in .Net 4.0 with the possible exception of the DDL features described in the last post. For that portion, the implementation and requirements are more clear to us, and because making the DDL stuff work requires changes to things already in the .NET framework, and getting provider writers lined up, we are still working hard to get the DDL changes into .NET 4.0. The rest of Code-Only will continue to evolve, and we will ship another preview or two, before getting it rolled into .NET as soon as we can after 4.0 ships.
Alex continues with the following topics:
- API Refactoring
- Foreign Keys
- Missing Navigation Properties
- Complex Types
- Registering Entity Sets
- Association Mapping
- Interesting Column Names
- Extracting the EDMX
- Setting the StoreType
- DDL Provider Model
Alex James posted Tip 37 – How to do a Conditional Include on 10/12/2009:
Someone asked how to do a Conditional Include a couple of days ago on StackOverflow.
They wanted to query for some entity (lets say Movies) and eager load some related items (lets say Reviews) but only if the reviews match some criteria (i.e. Review.Stars == 5).
Unfortunately though this isn’t strictly supported by EF’s eager loading, i.e. ObjectQuery<Movie>.Include(…) because Include(..) is all or nothing.
The workaround follows. (It’s obviously Alex James week on the Entity Framework team.)
LINQ to SQL
Ayende Rahien answers LINQtoSql Profiler & NHibernate Profiler - What is happening? in this 10/18/2009 post:
About two weeks ago I posted my spike results of porting NHProf to LINQ to SQL, a few moments ago I posted screenshots of the code that is going to private beta.
I spent most of the last week working on the never-ending book, but that is a subject for a different post. Most of the time that I actually spent on the profiler wasn’t spent on integrating with LINQ to SQL. To be frank, it took me two hours to do basic integration to LINQ to SQL. That is quite impressive, considering that is from the point of view of someone who never did anything more serious with it than the hello world demo, and it was years ago. The LINQ to SQL codebase is really nice. [Emphasis Ayende’s.]
Most of the time went into refactoring the profiler. I know that I am going to want to add additional OR/Ms (and other stuff) there, so I spent the time to make the OR/M into a concept in the profiler. That was a big change, but it was mostly mechanical. All the backend changes are done, and plugging in a new OR/M should take about two hours, I guess.
For LINQ to SQL, however, the work is far from over, while we are now capable of intercepting, displaying and analyzing LINQ to SQL output, the current LINQ to SQL profiler, as you can see in the screen shots, is using the NHibernate Profiler skin, we need to adapt the skin to match LINQ to SQL (different names, different options, etc).
That is the next major piece of work that we have left to do before we can call the idea of OR/Ms as a concept done, and release LINQ to SQL as a public beta.
Ayende Rahien’s LinqToSql Profiler private Beta - the screen shot gallery post of 10/18/2009 claims:
This is just to give you some ideas about what the new LinqToSql Profiler can do.
It can track statements and associate them to their data context, gives you properly formatted and highlighted SQL, including the parameters, in a way that you can just copy and execute in SQL Server:
Link Exchange shows How to Update a Database Using LINQ to SQL [Video] in this 10/12/2009 screencast, which follows the earlier How to Use LINQ to SQL to Query a Database [Video] of 10/12/2009.
The Developer Sneak Peak video includes a demonstration of LINQ to SharePoint and the Language Integrated Query (LINQ) for SharePoint section had a link to display sample LINQ to SharePoint code.
(This new feature undoubtedly explains why Aghy (Agnes Molnar) has been so quiet about her LINQ4SP project for the past few months and why Bart De Smet hasn’t rejuvenated his LINQ to SharePoint implementation.)
LINQ to Objects, LINQ to XML, et al.
The Data Platform Insider blog reports in its Get ready for SharePoint Conference Next Week! post of 10/16/2009 that SharePoint 2010 will gain a new LINQ to SharePoint implementation. Watch for the Developing with REST and LINQ in SharePoint 2010 (#SPC359 on Twitter) session when new SharePoint 2010 features are announced next week.
Miha Markic describes Dealing with iterations over null lists in LINQ to Objects in this 10/15/2009 post:
If you used LINQ to Objects you have certainly come across iterations over null values resulting in an ArgumentNullException being thrown at you.
Deborah Kurata continues her series on Lambda expressions in C# and VB:
- Lambda Expressions: Execution (10/16/2009)
- Lambda Expressions: Func Delegates (10/11/2009)
- Lambda Expressions: Action Delegates (10/11/2009)
- Lambda Expressions: Predicate Delegates (10/11/2009)
- Lambda Expressions: Syntax (10/11/2009)
- Lambda Expressions: Finding an Item in a Generic List (10/11/2009)
- Lambda Expressions: An Introduction (10/11/2009)
and a related post:
- Delegates (10/11/2009)
See Sam Gentile’s Focusing on Data – Try #3 post of 10/13/2009 in the “Entity Framework” section, which describes how he came to the conclusion that he needed to understand SQL:
ADO.NET Data Services (Astoria)
Rick Anderson’s MVC FAQ post of 10/15/2009 provides an extensive FAQ about MVC and Dynanic Data.
Alex James continues his Entity Framework Tips series with Tip 38 – How to use CodeOnly with Astoria. See the Entity Framework section for details.
ASP.NET Dynamic Data (DD)
David Ebbo’s T4MVC 2.4.04 update: MVC 2 support, new settings, cleanup, fixes post of 10/15/2009 shows you where to get the latest build of T4MVC and describes the changes between version 2.4.00 and 2.4.04.
Miscellaneous (WPF, WCF, MVC, Silverlight, etc.)
David Ebbo’s T4MVC 2.4.04 update: MVC 2 support, new settings, cleanup, fixes post of 10/15/2009 shows you where to get the latest build of T4MVC and describes the changes between version 2.4.00 and 2.4.04.