O'Reilly Forums: Ch 4: Different Behaviour With Vs2012 & Net 4.5 ? - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ch 4: Different Behaviour With Vs2012 & Net 4.5 ? I get different res. in "Shaped Data returned by Queries" samp

#1 User is offline   Pierre-François Culand 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 12-March 13

Posted 12 March 2013 - 08:08 AM

I'm just reading Programming EF (now at chapter 4) but trying all the code samples on VS 2012 and .Net 4.5.

Is that the reason why I get different results in the "Shaped Data Returned by Queries" sample p.108/109 (and also in the next "Shaped Data from Entity SQL" sample p.109/110, and in the "Deferred Loading Entity Collections with Load" sample p.111) ?

In the two Shaped Data samples (LINQ to Entities and Entity SQL) I do not get the same the output than in the book.

For the two registered addresses of Mr. Alderson I get the right address count:

City: Montreal, LastName: Alderson
LastName: Alderson, # Addresses: 2
.....Montreal

City: Montreal, LastName: Alderson
LastName: Alderson, # Addresses: 2
.....Montreal


Why do I get already 2 addresses when reaching the first address of Mr Alderson ???

In the "Deferred Loading Entity Collections with Load" sample p. 111 I first try to copy the code without the contact.Address.Load(); call to verify that I get all address counts to 0...

...But surprisingly, I noticed all the Address counts were right without an explicit loading ???

Is there something like new automatic dynamic loading functionnality beeing added to the .Net 4.5 ?

And if so, what about the remark you wrote in the first paragraph of the "Deferre Loading and Eager Loading Queries" chapter : "Consider a typical model for sales information. [...] Can you imagine if you queried for contacts, and without expecting it, the entire contents of the database were returned-because it was related?" ?

Thank you for your explanations.
0

#2 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 313
  • Joined: 17-September 08

Posted 13 March 2013 - 01:18 PM

oh dear you are using the 1st edition? That was written for VS2008 and the very first version of Entity Framework. If you are using VS2012 and .NET 4.5 (and EF5) I would throw that book away. I'm so sorry.

I haven't tried those samples with EF5 but I am guessing that the context is just being smarter about understanding right away that there are two related objects whereas with the FIRST version of EF, it wasn't able to figure it out so quickly.

Working with EF5 & .NET 4.5 in VS2012 is vastly different from what you'll experience in this book.

After you throw this book away, I recommend watching my brand new "Getting Started with Entity Framework 5" course on Pluralsight. Then get the newer books: DbContext & Code First and even the 2nd edition to fill in blanks.

I'm sorry to be the bearer of this bad and possibly expensive news.
Please contact me offline if you don't have a subscription to pluralsight: http://thedatafarm.com/blog/contact/

Julie
0

#3 User is offline   Pierre-François Culand 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 12-March 13

Posted 14 March 2013 - 12:05 AM

Oh really ?! (Maybe should I write "O'Reilly ?!") :)

Ok... let's say I prefer to learn this after chapter 4 than after having read the full obsolete book... ;-)

I recently changed my job and am still novice with C# and completely beginner with EF (I was previously working with Delphi and Firebird...)

I have to develop a new data centric industrial application in C# on VS2012 / .Net 4.5 and intend to use EF. I need a full fundamental knowledge of EF before starting the design of the app and its database. What would you recommend I start with to be ready ASAP ? (I've just ordered your two books "Context DB" and "Code First") Do I need to order the 2nd edition of PEF as well ? I will also have a look at your course on PluralSight. Please give me your advice for the fastest and most efficient way to learn that stuff quickly because the project timeline is, as usual..., very short.

Anyway, congratulation for your writing of PEF. It's very easy to read and very deeply detailed. I look forward to reading other books or courses you wrote.

Best Regards,
Pierre-François Culand
Switzerland.
0

#4 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 313
  • Joined: 17-September 08

Posted 14 March 2013 - 05:16 AM

I'm so sorry about this. Watch the getting started video on pluralsgiht. Then I recommend the code first book and the dbcontext book (maybe dbcontext first?). The fat book has some good details but I think between the two new books and the pluralsight videos you've got a great coverage. There are some good bits in the fat book like detailed querying (stick with LINQ, don't bother with Entity SQL ..these two are handled separately in the 2nd edition instead of intermingled in the first) and the chapter on security/transactions/etc in the 1st edition book don't really change that much. Even the performance guidelines are still relevant. But you can follow up by reading an MSDN doc called performance considerations for EF5.

It is painful to me that even the 2nd edition is challenging now (because with VS2012, the default is dbcontext, not objectcontext) and I thik often about revising the big fat book again but it is so much work and I prefer creating the videos.

Julie
0

#5 User is offline   Pierre-François Culand 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 12-March 13

Posted 15 March 2013 - 01:08 AM

Ok, I'm now reading the 2nd edition focused on EF4 / VS 2010 / .Net 4.

(But note that I'm still using the up to date software components: EF5 / VS 2012 / .Net 4.5)

And I finally found the answer to my original question at pages 98-101 in Example 4-29 (modified from the Example 4-49 of 1st ed.) and in paragraphs "Loading Related Data" and later in "Controlling Lazy Loading / Disabling and enabling lazy loading programmatically" (of PEF Ed. 2)

To get the same behaviour than in the book (Ed. 1 or 2) I had to add the following line when creating the context:

context.ContextOptions.LazyLoadingEnabled = false;

Because the VS2008's EF version did not support Lazy Loading but EF4 / VS2010 and EF5 / VS2012 set the LazyLoadingEnabled context option to true by default...

Ok, that answers to my original question.

But I'm still wondering something:

Concerning the remark at the end of first paragraph at page 100 of the 2nd ed.:

"Consider a typical model for sales information. A contact is related to a customer; a customer has sales orders; each sales order has line items; each line item relates to a product; each product comes from a vendor and is also related to a category. Can you imagine if you queried for contacts, and without expecting it, the entire contents of the database were returned--because it was related ?"

Is this really what will happen if I leave the default context option LazyLoadingEnabled property set to it's default value (true) ?

Or is Lazy loading of EF a bit smarter than that ?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users