If you’re tired of encountering the Entity Framework error message “The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects,” this blog post will help you understand why it happens and how to prevent it from happening again.
Tag: lazy loading
-
What is lazy loading in Entity Framework
In this article, you’ll discover why lazy loading with Entity Framework is so beneficial and how you can implement it yourself.
-
CakePHP 2.0 Rant Retraction
In yesterday’s article, it appears I may have misunderstood something regarding lazy loading. I incorrectly read it as “loading the data” on-demand oppose to loading the object on-demand. This actually looks like a great feature, especially after reading this: http://bakery.cakephp.org/articles/Frank/2010/08/10/optimizing-model-loading-with-lazymodel
It appears associated models would automatically be loaded simply because they are related to the model you are querying, even if you are not retrieving data from it.
Thanks for the clarification on lazy loading Jose and I’m actually quite excited to see this change after further research into the situation. Check out these benchmarks from the above mentioned article:
Before lazy loading
Total Requests made: 100
Total Time elapsed: 6.8480186462402 (seconds)
Requests/Second: 14.603 req/sec
Average request time: 0.068 seconds
Standard deviation of average request time: 0.002
Longest/shortest request: 0.078 sec/0.066 sec
Memory usage: 9.75MBPost lazy loading
Total Requests made: 100
Total Time elapsed: 4.8957378864288 (seconds)
Requests/Second: 20.426 req/sec
Average request time: 0.049 seconds
Standard deviation of average request time: 0.001
Longest/shortest request: 0.056 sec/0.048 sec
Memory usage: 7.25MBAlmost 6 full requests more per second! Just in the 100 requests made there is over 2 seconds being gained! Excellent work community!
-
CakePHP 2.0 Rant
I was recently visiting the CakePHP bakery and decided to read a little bit about CakePHP 2.0-dev. I’ve rather enjoyed CakePHP as a framework since version 1.1 all the way through to version 1.3. However, after reading some of the “features” for version 2, I have to say, I’m a little disappointed about their focus. (more…)