p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Visual Basic 2010 and .NET 4 (http://p2p.wrox.com/forumdisplay.php?f=578)
-   -   Code to output the LINQ query that groups doesn't work on my system (http://p2p.wrox.com/showthread.php?t=83143)

mangel April 1st, 2011 01:18 PM

Code to output the LINQ query that groups doesn't work on my system
 
Hi,

A suggestion to to author of Chapter 10 of this book, specifically of the LINQ piece of the chapter, to be a little bit more descriptive of the grouping part of LINQ to SQL part. The sample code for this used two nested 'for each' loops which I hadn't noticed while I was typing in the code for it. The result of course was that it didn't work. This was a change in the approach shown in the previous examples. But I think that there is something about LINQ that implies that the result of the query is really a collection of collections and, because that wasn't explained at all, I had difficulty with the sample. I think that on initial exposure to LINQ queries one has to change his/her mindset from SQL to OOP. But that doesn't seem to hit you until you want to do a GROUP BY query in LINQ. I know that that is one of the characteristics of LINQ to SQL, but I think the idea really needs to be fleshed out when doing GROUP BY queries. Then the reader will truly begin to understand LINQ.

Because LINQ is new to me, I may be incorrect here; if so, an explanation would be useful. I know that the book deals with a whole lot more than LINQ, but I intend to read what it says about LINQ before I move on to a book that is dedicated to LINQ and VB .NET 2010. By the way, WROX doesn't have one.

Thanks,

Mike

ksharkey April 1st, 2011 11:05 PM

Hello,

Thank you for the idea. I'll try to keep it in mind in the future.

mangel April 4th, 2011 04:39 PM

One more suggestion
 
I believe that to be most helpful to the reader of the LINQ section of Chapter 10 the author should put all the sample code into one project. The reason is that doing so will create a few issues that do not show up when each code example is put into a separate project.

My inclination as I was reading was to do it this way. The result was that I had to work through a few gotchas that were not explained in the book.

Thanks to Imar I got the answers I needed. The solution was to instantiate the data context separately for each example, execute the sample code, and then dispose of it using its dispose method. This would have been necessary if one project had been used in order to get it to work in all cases.

I also put each sample, especially the ones with database updates involved, into a separate try/catch block.

Thanks,

mangel


All times are GMT -4. The time now is 08:00 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.