views:

445

answers:

3

I'm about to start working on a new project and am wondering if "Code Only" is the right way to go. We're also considering the other model-first approach through the designer, but would rather design my domain models outside of the EF designer.

Our domain will likely contain 100+ entities. I've read that a huge number of entities can somewhat slow down EF (ie: Creating the context and first call to SaveChanges).

Since there's no EDMX file to store the metadata, is this approach likely to be slower? I've searched the web but haven't been able to find any information on this.

I know this is still only in CTP and missing lots of functionality, but I'm just looking for input/guidance at this point.

+1  A: 

As .NET 4, including EF4 is Beta 1 currently you are not going to get any useful general answer. For your specific case why not test.

Create an entity model with one entity and run some performance tests. Then expand the model to have more entities and re-run the test. If there is a performance impact of the number of entities in the model you should see a performance difference.

Remember to discount load effects, unless you are only interested in applications that start up, perform a single operation and then shutdown.

Richard
It's not quite the answer I was looking for, but given the context it's probably the best (only?) thing to do
Joepro
+2  A: 

Internally Code-Only caches metadata so, once the first context has been created you should see very little difference in performance between Code-Only and the EDMX approach.

You are right that a large number of entities can slow down EF.

Pregenerating Views is often recommended to help performance with large models. But that feature relies on having an EDMX file, so not surprisingly it doesn't work with Code-Only.

However if you find you need to pre-compile views you could always to use the ToEdmx() feature of CodeOnly to move from the CodeOnly world to the standard EDMX world. And of course once in the EDMX world you can pre-compile your views.

However this is not necessarily the approach I would take.

I think a context with 100 or more IQueryable properties is less than ideal from a useability perspective anyway.

So rather than move away from Code-Only to pre-gen views, I'd probably leverage Code-Only's ability to make it easy to create smaller targeted subdomains, to minimize the effective size of the model for the part of the App you are working on.

The result would be a number of fast, easy to use ObjectContexts, targeted for the current set of tasks.

Which IMHO is much more desirable.

Hope this helps

Alex

Alex James
+1: this is generally true. See http://stackoverflow.com/questions/1481754/entity-framework-v4-code-only-performance-considerations I wish, however, that all EntitySets weren't automatically properties of the ObjectContext (or at least could be turned off). Ideally, only aggregate roots would be public properties.
Craig Stuntz
Oops. Wrong link. Should have been http://devlicio.us/blogs/casey/archive/2009/05/14/commercial-suicide-integration-at-the-database-level.aspx
Craig Stuntz
We explicitly went out of our way to support aggregate roots in code-only. For example you can have an ObjectContext with just one ObjectSet<> but it can easily have multiple EntitySets. Easy to configure too.
Alex James
I really like the idea of having multiple ObjectContexts and being able to configure them to my needs. Seems like Code-Only IS the way to go and can't wait for the next release. Thank you both.
Joepro
Yes, I agree. Code-only supports the aggregate root concept well. But I'm still using v1, and when I migrate to v4 I can't see that it will be easy to go to code-only. We'll see. For DB first and model first, it would be nice if I had a "Visibility" property (public/private) on the EntitySet.
Craig Stuntz
Yeap... Something I've been advocating for a while. Not in .NET 4.0 though.
Alex James