Jeffrey Palermo (.com)

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
We'll see Microsoft's OR Mapper soon - level 100

Many long-time Microsoft developer hold fast to the "all data access must be stored procedures" thought, and that was, at one time, the guidance from Microsoft.  Soon we'll see the Object-relational mapper from Microsoft in the form of Linq for Entities.  I drove up to the North Dallas .Net User Group yesterday and visited with Scott Guthrie on the topic.  Microsoft has tried a few times before at creating an OR mapper, but they've learned from past attempts and are releasing v1.0 of Linq as their entry into the ORM space.

I'm very much entrenched in the ORM space with NHibernate, but I'm interested in how Linq for Entities pans out.  From a cursory look, the mapping information is specified with attributes that are placed on the entity class.  I'm not sure if that's the only method for this, but I'm very much looking forward to the release.

An interesting tidbit demonstrated was the server-side paging of a Linq query.  For instance, the C# query: from customers select customer, you can specify to skip 10 and then return 10 (or any number) if you need to page through the resultset 10 at a time.  Linq will formulate the SQL query to get you exactly what you want.  Very nice.  Ayende, in the comments below gives an example of that with NHibernate.


Posted Fri, Nov 3 2006 9:08 AM by Jeffrey Palermo

[Advertisement]

Comments

Ayende Rahien wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 12:07 PM
Paging with NHibernate: session.CreateQuery("from Post") .SetFirstResult(10) .SetMaxResults(10) .List();
Udi Dahan - The Software Simplist wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 12:24 PM
O/R mapping is a poor fit for reporting like operations, in my opinion. It just wasn't really designed for it. On the other hand, I don't think that LINQ was designed to give me the polymorphic "get" that NHibernate does. The whole issue of mapping a class hierarchy, and getting back the appropriate object which special cases the behavior enables us to write true OO persistent objects. Paging, like reporting, is not something O/R mappers were designed to do well. Use LINQ for it.
Jeffrey Palermo wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 1:54 PM
Ayende, thanks a bunch! I love my blog. It's better than a forum post! These are the kinds of things I love finding out.
Jeffrey Palermo wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 1:58 PM
Udi, Yes, I can see how those are different paradigms. Up to this point, my team has been very happy with NHibernate (and I personally started using it about a year ago) including the little bit of reporting we do. The few times I have gotten into hairy querying situations, I've been able to hand-craft the query and return only the IDs of the objects I need to return. Then I ask NHibernate to get me those objects where the ID is "IN (. . .list. . .)"
Ayende Rahien wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 9:53 PM
@Jeremy, You can get entities from a custom SQL query, using CreateSqlQuery() This saves a DB query. Although, when you need to do wierd stuff with the report, specifically, presenting this as something that is very different than the data / object model
Ayende Rahien wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Fri, Nov 3 2006 10:03 PM
@Udi, I really disagree about thinks that O/R isn't supposed to do paging / reporting. Speaking specifically about NHibernate, it has a great support for both of those. These features are not usually covered in details in most tutorial, since they focused on getting stuff working in small measures, not the complex problems you find yourself facing 50% into a project.
Sam Gentile wrote New and Notable 122
on Sat, Nov 4 2006 9:41 AM

Family morning at the Gentiles means the whole family watching Radiohead from 1994 while waiting for

Tom Dean wrote re: We'll see Microsoft's OR Mapper soon - level 100
on Sun, Nov 5 2006 6:50 PM
In web development, at least, paging is imperative to performance. Lack of decent paging with an OR/M wrapper is liking giving a mechanic all the tools he needs except a screwdriver.
Sam Gentile wrote New and Notable 122
on Sat, Oct 20 2007 3:33 PM

Family morning at the Gentiles means the whole family watching Radiohead from 1994 while waiting for

Devlicio.us