Skip Ribbon Commands
Skip to main content
Navigate Up
Sign In
Tim's Blog > Posts > Thoughts on the Entity Framework Vote of No Confidence
June 23
Thoughts on the Entity Framework Vote of No Confidence

I'm far from an expert on Microsoft's Entity Framework (EF), but I have dabbled a bit with betas 2 and 3. Recently, Brian Ellis, a colleague of mine, summarized the points made in an open letter claiming a "vote of no confidence" in the Entity Framework. I'm no ORM guru or EF junkie, but I know enough about EF to see that it has both potential and limitations. I'd like to share my thoughts on the letter.

To be fair, I've never used NHibernate (the Holy Grail), and work primarily with Microsoft technology. That doesn't make me an EF evangelist. I'm still quite skeptical, but interested in understanding the value of the technology.

Before getting into the issues mentioned in the open letter, I would like to add a few gripes of my own:

  • The design surface is not feasible for maintaining hundreds of entities.
  • The mapping seems to be brittle when using the designer for custom entities, including the refresh from schema feature.
  • The designer forces the developer to refresh from schema in certain cases, when perhaps she doesn't want to.
  • Generated code in an entity data model does not represent self-referencing schema very well (for instance, an Employee that inherits from Person, which has a Manager property that also inherits from Person). Customizations required to work around the issue are hard to maintain.

I'm sure the more I use it, the more gripes I'll have, but for now let's get to the gripes of the open letter.

 

INORDINATE FOCUS [ON] THE DATA ASPECT OF ENTITIES LEADS TO DEGRADED ENTITY ARCHITECTURES

Regarding the point that entities are tied too closely to schema, I believe this is often true, but only because unmodified, generated code is the simplest and most common way to build an entity model—straight from schema. They don't have to be, however. From my understanding, a decent amount of flexibility is provided for structuring entities and their relationships, included multiple inheritance patterns, and the ability to group mapped columns into complex object properties.

(For instance, a Person table may contain several columns related to addresses. You could create a complex type called Address that a Person entity uses, and map the properties of the Address property to the columns in the Person table. No Address table is required in the data store, just proper mapping.) I'm sure, however, that many entity models would be very difficult, or impossible, to map using EF.

Regarding the point that entities are data-centric, rather than behavior-centric, I might not fully understand the complaint. The authors make no mention of the fact that the entities are partial classes with full exposure to the EF's data access gateway, allowing custom business and data access logic to be attached to each entity. (They do mention the partial class architecture in the "persistence ignorant" section, but only to complain of its "awkwardness.") It seems to me that custom entities could be designed with behavior in mind.

EXCESS CODE NEEDED TO DEAL WITH LACK OF LAZY LOADING

EF supports deferred loading, but requires the developer to understand when any related entities ("navigation properties") are loaded, rather than automatically fetching & load-tracking when referenced. It's true, this causes the developer to ask IsLoaded() of an entity's navigation properties, and then conditionally Load(). You can also eagerly fetch navigation properties when fetching the parent by using the .Include() method, but this is pretty much the opposite of lazy loading. It sounds like the authors of the letter do not want developers to need to understand when or if a property has already been loaded. I don't really have an opinion on this since this requirement hasn't given me enough heartburn to gripe about it.

SHARED, CANONICAL MODEL CONTRADICTS SOFTWARE BEST PRACTICES

If I understand correctly, the authors of the letter are proponents of separate models per application tied to a single data store, rather than a single, canonical, model shared by multiple applications. This seems fully feasible with EF—there's no reason multiple models could not represent and access the same data store. Am I missing something?

Even better in certain cases, it seems possible with EF to place all core, sharable logic in a shared entity model, and have application-specific logic in each application that consumes the model. This architecture would probably break the partial class pattern of putting the logic directly in the entity, but if the logic is application-specific, I don't think it belongs there anyway. This could be handled with a more classically-tiered approach using service layers or business layers in consuming applications.

LACK OF PERSISTENCE IGNORANCE CAUSES BUSINESS LOGIC TO BE HARDER TO READ, WRITE, AND MODIFY, CAUSING DEVELOPMENT AND MAINTENANCE COSTS TO INCREASE AT AN EXAGGERATED RATE

I think this is a little misleading, because the entities themselves are persistence-ignorant, but obviously the mapping configuration cannot be. Perhaps I'm missing something, but that seems to be the nature of ORM. In order to connect an entity data model to two completely different data stores (in schema, technology, etc.), you would have to take great care in creating two separate mapping configurations to ensure they provide equivalent mapping. Even then, you are limited by the differences in what the two data stores support. For instance, you can't expect an XML file to support cascading deletes or other features that SQL Server provides. However, if we ignore the differences in the features of data store technologies and focus solely on mapping, I believe the EF supports persistence-ignorant consumption of entities, allowing for unit testing, data migration, etc.

EXCESSIVE MERGE CONFLICTS WITH SOURCE CONTROL IN TEAM ENVIRONMENTS

This wouldn't surprise me, but I have no experience with EF in source control.

 

In summary, I feel like the open letter attempts to make some good points, but doesn't do much to back them up. It also seems that certain features of EF are glossed over, or perhaps EF is just not enough like NHibernate for those that wish it was. I'm not an EF evangelist, and I'm sure when it's finally released it will stir up a lot of complaints (by me, included), but this letter smells a bit like alt.net vs. MSFT to me.

 

 

Comments

Re: Thoughts on the Entity Framework Vote of No Confidence

The perspectives in the letter are fed by many years of experience in building entity-based applications using the various techniques and frameworks that our evolving awareness of issues led us to along the way.

It's great that you're questioning the validity of the claims of the letter and expressing your perspective.  I don't think that we can possibly have the same perspective because of the different experiences between us.

Frankly, we can't really argue this issue on a peer level.  You'll have to practice entity-based designs within the context of practices that support reversability and the levels of productivity we get from choices of tooling and approach that have been honed by quite a bit of time invested in trial and error over the years.

And yes, I know that you can take this comment as pomp and arrogance.  That always seems to be the risk in the .NET developer community when we tell someone that there's much more experience to be gained and much more learning to do.

You may choose to use EF, and to use the increasingly-antiquated approaches to software development that gather around tooling like EF, and you may never know the difference in the advantages and advances that underpin the EF letter.  That doesn't mean that those advantages aren't there.  It only means that you may not have done the exercises that tune your perception so that you can see them.
 on 6/24/2008 7:37 AM

Re: Thoughts on the Entity Framework Vote of No Confidence

Thank you for the response, nameless one.

I appreciate your in-depth explanation of how experienced you are with building entity-based applications. Unfortunately, I didn't find anything in your post addressing the questions I have about the Entity Framework. I understand, as you point out, that we can't discuss this subject as peers, but perhaps we could do so under another relationship. How about…you be the experienced entity application guru, and I'll be the wide-eyed student who posted some questions about the Entity Framework. Cool?

Under this relationship, you can safely share a bit of knowledge, and I’ll just listen. I'll probably just respond with grunts and glassy-eyed head nods, but at least you'll be addressing the specifics of the original post and contributing to the public knowledge base, rather than just telling me how smart you are.

Let’s start with this one: How did the architects of EF "force entity objects...to become merely data objects," and why does that section of the open letter not mention the partial class implementation of entities? In what way does adding behavior to an entity's partial class when creating a behavior-centric entity fall short in the eyes of the open letter's authors?

That’s the type of stuff I want to understand. I’m sure I’m just way off, and missing something major. Unfortunately, the open letter makes a lot of abstract claims, but doesn't put a lot of meat on my plate.
Tim LeeNo presence information on 6/24/2008 5:24 PM

Data centric

Tim,

As the guy who wrote at least one version of the doc (and apparently did it poorly), I'll take on the "force entity objects...to become merely data objects,"

Yes, you can certainly put business logic into the partial classes and regen the data part of the entity.  I think that's awkward as all hell, especially compared to classic OO where the fields, properties, and business logic are in the same file where you can read and understand everthing in one place.

However, the bigger concerns for me are:
A.)  Can I use a domain model structure that's optimized for the desired behavior while using a somewhat different database structure that's optimized for storage concerns?  That's where the EF goes wrong with its focus on the database first.

B.) Can I focus on the behavioral aspect of the domain model independently of the persistence?  With EF, the only efficient way to use it in V1 is going to be codegen-ing the entities from the Xml models.  Personally, I find that to be very awkward compared to just flat out coding a domain model.

You still might not agree, but a large reason I'm on the EF signatory list is so I don't have to be forced to develop software the EF V1 way when it becomes the de facto standard.
 on 6/24/2008 9:13 PM

Re: Data centric

Now that's the kind of response I'm looking for -- thank you! I think if the open letter contained specifics, such as the ones you've just presented, it would be much more effective. Without concrete evidence, it's hard to not be skeptical of it as merely an anti-MSFT campaign.

I'd like to continue this conversation, if possible. Maybe I could comment a bit on your helpful post.

[quote]Yes, you can certainly put business logic into the partial classes and regen the data part of the entity.  I think that's awkward as all hell, especially compared to classic OO where the fields, properties, and business logic are in the same file where you can read and understand everthing in one place.[/quote]

Currently, I'm working on a project that uses a much more rudementary n-tier code generator, where the generated classes in each tier are extended by partial classes. Since the generated portion is never touched by a developer, I haven't found this separate-file pattern to be awkward. However, code-generation, in general, is not only awkward, but quite limiting. I share your sentiments to some extent.

[quote]Can I use a domain model structure that's optimized for the desired behavior while using a somewhat different database structure that's optimized for storage concerns?[/quote]

I've played around a bit with mapping domain models in EF that are "somewhat different" from the database structure, and tend to agree that the further you get from the database structure, the harder it is to map. Maybe I just don't know where the technical limitation is, as opposed to my own limit to how hard I'm willing to try to get it to work.

[quote]Can I focus on the behavioral aspect of the domain model independently of the persistence?  With EF, the only efficient way to use it in V1 is going to be codegen-ing the entities from the Xml models.[/quote]

This seems to depend on a) can you live with the partial class pattern, and b) how far can the model deviate from the database and still be mapped with EF? It seems that if the behavior-centric model can be properly mapped, the answer would be "yes." But as mentioned previously, mapping gets tough (and I suspect impossible at some point) with certain domain models, and maintaining the seemingly-brittle XML for code-gen is a hassle.

[quote]Personally, I find that to be very awkward compared to just flat out coding a domain model.[/quote]

I've read a couple posts on using EF to map completely hand-coded model classes, and it seemed a bit painful, but doable. I'm curious how many people have tried this because we're considering it as an option in a project I'm on.

Thanks again for your response!
Tim LeeNo presence information on 6/25/2008 12:21 AM

Cutting off Their Noses to Spite Their Faces

Open Letter
Dear EF Petitions,

I have read the online petition and don't know what you aim to gain from this?  Complaining about whether implicit lazy loading and canonical shared models should be supported is ridiculous in a beta product.  Although, your criticism was constructive.. creating a public forum is frankly "Cutting off your noses to spite your face ".  I'm personally dismayed with the MVPs who signed, they should know better.  Most of you have direct connections into the product team and can express these opinions directly to them.  Why do this in public?   I have a lot of friends in Microsoft not just because they are business colleagues but hard working individuals who have spent 11 hour days trying to create something unique.  What if you were told your code is crap… see what I mean?
 I think that you’re missing the point with the EF.  Although it has issues, it’s the first issue.  I would like to see of your code to see if you get it right first time. 
The transparent approach announcement will prevent this type of thing happening again.  If you have this press release why don’t you back down?  Personal glory.. or just kicking the big guy?

Anonymous
 on 6/27/2008 12:32 PM

Expanding on Data centric

Just to expand on the Data centric comment above, an issue with EF and designer generated classes is that it is difficult to have 2 different databases access the same entities.  In the project I am working on, I want to access two slightly different database structures using the same domain entities.  This might be possible in the EF (not sure) but I haven't found an easy/obvious way to do it yet
 on 9/16/2008 7:34 AM

HjFUBdTkYfwiUkVrmqX

 on 6/25/2009 2:23 PM

HjFUBdTkYfwiUkVrmqX

 on 6/25/2009 2:24 PM

HjFUBdTkYfwiUkVrmqX

 on 6/25/2009 2:24 PM

Jason Jones

I would like to understand what is meant by "canonical models" in the complaint.  Does this mean that you want one EF model for each domain area (like Sales, Purchasing, Reporting, etc.), one model per application, or one model for group of applications? (Or is it referring to something else?)  What approach is considered best practice and why?
System Account on 11/22/2009 11:37 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


CommentUrl


Attachments