4

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.

3
  • The people who think that lots of entities slows down the first use of the context are the people who haven't found the compile-time view generation feature yet. Commented Sep 29, 2009 at 14:15
  • Alright, that's interesting. But does this feature work with "Code Only"? Commented Sep 29, 2009 at 14:59
  • I don't know. Maybe Alex James will chime in? Commented Sep 29, 2009 at 23:37

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

6 Comments

+1: this is generally true. See stackoverflow.com/questions/1481754/… 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.
Oops. Wrong link. Should have been devlicio.us/blogs/casey/archive/2009/05/14/…
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.
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.
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.
|
1

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.

1 Comment

It's not quite the answer I was looking for, but given the context it's probably the best (only?) thing to do
0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.