Sunday, July 26, 2009

LINQ and Entity Framework Posts for 7/20/2009+

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

Entity Framework and Entity Data Model (EF/EDM)

Gunnar Piepman demonstrates Entity Framework 4.0: Generating SQL script from model in this 7/23/2009 post:

Entity Framework 4.0 is able to generate database schema based on model. If you built your model first and you now want to create database for it you can use new Generate Database Script from Model feature. Let’s see how it works. I will use my example gallery model .

Alex JamesCustomizing T4 Templates post of 7/22/2009 shows you how to “re-use the code from his recent Entity Framework POCO template walkthrough post to “modify the generated code to do some validation, … using a Regular Expression.”

Julie Lerman reports a Small EF4/WPF bug that bit me in the butt during my VTdotNET presentation on 7/22/2009 that involves a customized T4 template and a Custom Tool setting.

Alex James continues his Entity Framework tip series with:

Julie Lerman also was Checking out one of the new stored procedure features in EF4 on 7/22/2209 and found “that it is now simple to call the function in your code without spinning up and executing an EntityConnection and EntityCommand.” She also lamented Life without EF or any ORM the same day.

Matthieu Mezil’s How to have FK in EF v1? post of 7/21/2009 shows you how to add a foreign key property to populate a DataGridViewComboBoxColumn and the ASP DropDownList with a T4 template.

Tony Sneed’s What’s New and Cool in Entity Framework 4.0 article for DevelopMentor explains “the new support for POCO and n-tier applications in EF 4.0.”


Chris Swain’s Linq to Sql WCF Service Generator post of 7/25/2009 begins:

The thought is that if we could just expose our server application data through a controlled interface, then a variety of client applications could make use of it and all would be right with the world. (Okay, well maybe not that last part.)

The hard part is writing all of the plumbing code to expose your data to the world in the form of a service. WCF has made this much easier for us by generating the WSDL and exposing various attributes to allow us to mark code items related to our service. Then it’s just a matter of writing some methods that you want to expose to the world and adding the appropriate attributes to them. Pretty easy, right?

But what about those instances when you have a very complex database with lots of tables and even more stored procedures? Well, assuming you’re using Sql Server as your database and you can create a Linq to Sql data access layer, then the Linq to Sql WCF Generator Item Template can help.

The i-think Twenty-Two blog’s LINQ to SQL and tables with no Primary Key observes:

I ran into an interesting issues with LINQ to SQL yesterday. I had to update a table with no Primary Key. As I expected, LINQ to SQL wasn’t too happy with this scenario. Unfortunately LINQ to SQL will only throw an exception when you try to Insert or Delete a record with no primary key. Updates fail silently. …

Without a primary key the two following interfaces aren’t emitted: INotifyPropertyChanging and INotifyPropertyChanged

Therefore LINQ to SQL doesn’t know that your record has changed (so can’t warn you that it can’t update).

Now that you understand the problem the solution is simple: Define a primary key in your table.

LINQ to Objects, LINQ to XML, et al.

Ayende Rahien reports in his NHibernate Linq 1.0 released! post of 7/26/2009 that LINQ to NHibernate has RTW’d:

The most requested feature for NHibernate for the last few years has been Linq support, and it gives me great pleasure to announce the release of NHibernate Linq 1.0 RTM, which you can download from here.

NHibernate Linq support is based on the existing, proven in production, Linq provider in NHibernate Contrib. The plans to overhaul that and merge that into NHibernate’s proper for the next release are still active, but the project team feels most strongly that production quality Linq support is something that we ought to provide for our users now.

This Linq release support just about anything that you can do with the criteria API. We do not support group joins or subqueries in select clauses, since they aren’t supported by the criteria API. NHibernate’s Linq support has been tested (in production!) for the last couple of years, and most people find it more than sufficient for their needs.

We do plan for expanding the Linq support to support more, but the decision has been made that it makes absolutely no sense not to provide an interim, highly capable, release in the meantime for our users. …

LinqMaster explains Using IEqualityComparer and Lambda Expressions in this 7/26/2009 post:

Anyone using LINQ to manipulate in-memory collections is probably also using plenty of lambda expressions to make things quite easy. These two additions were really meant for each other. One of our interns here recently ran into an interesting problem while using LINQ. As a relatively new user of .NET based languages, reference types caused him a bit of trouble.

Brian MainsLINQ to XML: Non white space characters cannot be added to content post of 7/25/2009 notes “I got this error when setting up some LINQ to XML code and I couldn't figure out why I kept getting this error as it made no sense.”

Jim Wooley reports his Site updated with MVC on 7/24/2009. His MVC Sitemap Navigation with XML Literals post of 7/22/2009 describes part of the update process.

Beth Massi describes her Channel 9 Interview: LINQ Language Deep Dive with Visual Studio 2008 of 7/21/2009 as follows:

In this interview I sit down with Jonathan Aneja, a Program Manager on the Visual Basic Compiler team, who dives deep into these features like Type Inference, Anonymous Types, Lambda Expressions, Expressions Trees, and more. He explains what's actually happening behind the scenes and all the work the compiler is doing for you when you write a LINQ query.

ADO.NET Data Services (Astoria)

No significant new Astoria articles this week.

ASP.NET Dynamic Data (DD)

David Ebbo’s Using an Associated Metadata Class outside Dynamic Data post of 7/24/2009 begins:

A while back, I blogged about how ASP.NET Dynamic Data apps can uses an Associated Metadata class (aka a ‘buddy’ class) to add metadata attributed to properties defined in a generated class.  It’s a mostly ugly thing that was made necessary by limitations of the C# and VB.NET languages: they don’t let you add attributes to properties defined in another partial class.

What I didn’t mention there is that this ‘buddy’ class mechanism is actually not specific to Dynamic Data apps, and can in fact be used anywhere.  Since I’ve recently heard of several cases of users trying to do something similar, I’ll describe how it’s done.  If you’re familiar with TypeDescriptionProviders (which have been around since ancient times), this will look very trivial.

Rick Anderson’s Using DataAnnotations in MVC 2 - Catching up to Dynamic Data post of 7/23/2009 appears to be missing most of its intended content. If Rick wrote an article for MSDN Magazine I couldn’t find it.

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

Aaron Skonnard’s RESTful Services With ASP.NET MVC article for MSDN Magazine’s July 2009 issue “describes how to use XHTML and ASP.NET MVC to implement REST services.”

Justin Etheredge describes Building Testable ASP.NET MVC Applications in MSDN Magazine’s July 2009 issue.

blog comments powered by Disqus