Linq to Entities: Microsoft’s first go at O/R Mapping (they need our feedback now!) – level 300

First, none of this is NDA.  Others discussing it are Ayende and Sam.   Here's a quick rundown of how you would get Linq to entities working:

  • Create the metadata file using the wizard.
  • Select some database tables to map to objects.
    • Wait for the designer to generate the mapping meta data.
    • Wait for the designer to generate some partial classes that might serve as entity objects.
  • Add code to these new classes to do interesting things within your domain.
  • Using Linq queries to work with these objects and watch the SQL be generated and sent to the database.

This sounds easy  when you remember that the designer is generating all the ugly goo that _has_ to be there.  First, the classes must inherit from the mapping base class.  They are working on a way to make it implement an interface instead.  This is a non-starter first of all because it would require the domain assembly to carry around a reference to a data access dependency.  Next, for dirty-tracking, each property mutator must raise an event to let the framework know that a property changed.  Every property.  Let me repeat:  Every property setter must raise an event for dirty tracking to work.  This is another non-starter.  The team plans to have all this generated for you in partial classes. 

I have email addresses for several people on the team, and I'll be letting them know what is so compelling about NHibernate and why the above issues have to be resolved before RTM and not after.

In some cases, you don't care if the classes are data-transfer objects instead of domain objects.  In that case, use Linq to SQL, not Linq for Entities.  With Linq to SQL, you can use DTOs all over the place and work with the data pretty easily.  Heck, you could even use Linq to SQL to create your own data layer for hydrating your domain objects manually from the DTOs you decorate with the Linq to SQL attributes.

Linq to Entities is a different animal and is meant to persist domain objects.  Domain objects ARE the most important part of the application.  The domain defines the business problem scope.  Persisting to a data store is secondary to the domain model's structure and behavior. 

I want Linq to Entities to succeed.  I want frameworks and tools to continually get better; therefore, I will be communicating with the product team to voice my strong concerns over the current direction.

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

10 Responses to Linq to Entities: Microsoft’s first go at O/R Mapping (they need our feedback now!) – level 300

  1. Colin Jack says:

    Yikes. Deriving from a few interfaces isn’t the end of the world, not great but we could do it, but the properties bit is just awful. If its auto generated then it is not so bad but still….

  2. > it would require the domain assembly to carry around a reference to a data
    > access dependency

    Jeffrey,

    This isn’t really a problem unless you’ve got a constraint that doesn’t allow you to distribute the domain object component with the data access component, or a constraint that suggests that it’s inappropriate to do so. Most web apps don’t have this constraint, but many distributed smart client apps would.

    Components are only units of distribution. The only real force dictating their shapes is the app’s distribution model.

  3. Angel Saenz-Badillos says:

    Ayende,
    “I am finding it hard to get publicly available information about EF”

    Interesting comment, I would like to know what you feel is missing from the EF message. Our blog at http://blogs.msdn.com/adonet/default.aspx is fairly active, if you don’t see something that interests you feel free to post a comment there

  4. jpalermo says:

    I don’t think there is any documentation yet, just the bits. I spoke with the Entity Framework architects today, and the roadmap is actually quite bright, so I’m less concerned now. I think they are on the right track, but it will take a while, so don’t expect to have your domain-centric O/R mapper in Orcas. I’m not sure what I can disclose, but I’ll find out and blog an update.

  5. Scott says:

    This is their second foray into this realm (remember ObjectSpaces?). It looks like the designer for this is different. My big question is: What’s the ROI look like vs. using NHibernate/WilsonORMapper/LLBGen/Gentle.net?

  6. sergiopereira says:

    @Ayende, I’ve trying to get on top of that too and I have been collecting some links. Maybe you can find one that you haven’t seen yet over here: http://del.icio.us/sergiopereira/entityframework

  7. I am sorry, I know all of that, and I already have the CTP.
    What I am interested in is stuff beyond the very high level overview + maybe hello world.

  8. @Jeffery,
    I am finding it hard to get publicly available information about EF.
    Can you point me to some sources?

Leave a Reply