r0k3t (3) [Avatar] Offline
#1
Opps - I am still on the first edition of this book. Is there some where I can get that code?

I downloaded fullsource.zip but chapter 12 doesn't compile so i am assuming it is for a newer version of Visual Studio... I am using 2008.

Or maybe I have the right version but I am just totally confused - the problem I get when I try to open DefectDataSet.xsd is that it is complaining "Column requires a valid type" - also if I just whack on the F5 key I get the following...

Error 2 'System.Array' does not contain a definition for 'AsParallel' and no extension method 'AsParallel' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) C:UserskennC#InDepthSourcefullsourceC# In DepthChapter12ParallelLinqRandomSleep.cs 29 44 ParallelLinq




Thanks!
mgravell (64) [Avatar] Offline
#2
Re: Sample code from the first edition?
To compile that in VS2008 will require the Parallel LINQ (PFX) CTP (a separate download). To be honest, though; at this point it may be worth waiting until VS2010 / .NET 4.0 is fully available, and use the final version.
jon.skeet (451) [Avatar] Offline
#3
Re: Sample code from the first edition?
Marc's absolutely right about the Parallel LINQ project. I'm not sure why DefectDataSet.xsd doesn't work - it certainly should, and that code was written before VS2010 came out even as a beta.

I've just downloaded the source from the web site and rebuilt it myself in Visual Studio 2008 SP1, and it's fine - perhaps you need the service pack?

Hopefully it won't be long before the second edition source will be up though smilie
r0k3t (3) [Avatar] Offline
#4
Re: Sample code from the first edition?
Correct you are folks... i am missing the Parallel Linq extensions however I spent like 45 minutes trying to find the link for them, I keep finding stuff for visual studio 2010 but just can't find the update for 2008... Does anyone know where I can get this? It's making me feel like a knucklehead - I can't seem to locate a simple update for visual studio.
jdfagan (4) [Avatar] Offline
#5
Re: Sample code from the first edition?
I just read 1st edition last week and had similar errors when trying to compile for Visual Studio 2010 (version 10.0.30319.1 RTMRel). I got past the AsParallel issue by making the ParallelLinq project a .NET Framework 4 targetted framework and then getting rid of the 3 param value passed into the AsParallel method in RandomSleep.cs:

//var query = from name in names.AsParallel(3)
var query = from name in names.AsParallel()
select ObtainLengthSlowly(name);

However, I'm still having issues with the DefectDataSet.xsd I believe - with following error which I believe is root cause to many other errors I'm getting from DefectModel.edmx and DataSetExamples.TypedGroupOpenDefectSummariesByStatus:

Custom tool error: Failed to generate code. Column requires a valid DataType.

When I double click this error in VS 2010, it highlights line 2 of the xsd file. I was guessing that perhaps the references to DefectModel.xsd were no longer valid:

http://tempuri.org/DefectModel.xsd

I googled around and was wondering about that tempuri.org URL. Seeing other references by Microsoft, I attempted to change the above URL references to this but still no dice:

http://schemas.tempuri.org/DefectModel.xsd

Has anyone got the edition 1 code working on VS 2010? I can't figure out what's wrong with the xsd file - DefectDataSet.xsd and it referring to DefectModel.xsd which may or may not exist as I don't seem to have this xsd file from the downloads.

JD
jon.skeet (451) [Avatar] Offline
#6
Re: Sample code from the first edition?
Yes, I'm afraid PFX has changed somewhat since the first edition was published. The second edition's PFX code works against .NET 4.

I'm not sure what's wrong with the DataSet examples - to be honest, those examples are removed from the second edition as I no longer use LINQ to DataSet. The same is true for the Entity Framework example. I'm happy to try to get both working, but it's likely to be after the second edition is released.

In VS2008, after unloading the PFX project, everything builds for me... I don't know whether this is an incompatibility between .NET 3.5 and .NET 4, or something going wrong in the conversion process...

Jon
jdfagan (4) [Avatar] Offline
#7
Re: Sample code from the first edition?
Well, I got it to finally all compile with VS 2010. By the way, I am using SQL Server 2008 (full version not express) and I forgot to mention the tricks I did to port over your mdf files to 2008, so that could also be part of my complications. Here's what I ended up doing to get everything to compile with VS 2010 with SQL Server 2008:

* Altered security for mdf, ldf files to temporarily be Everyone full control. This makes it a bit easier for SQL Server 2008 to then attach to these database files and adds them to SQL Server 2008 set of databases visible now via Enterprise Manager.
* ParallelLinq project to .NET 4; fix AsParallel(3) to be AsParallel()
* DataSetExamples - deleted existing DefectDataSet.xsd. Added new Dataset Datasource to point to my local SQL Server -> which then prompted me to create Settings connection string. I then copied this connection string value into the value for SkeetySoftDefectsConnectionString. Also, a new xsd was created. This seemed to correct my errors with the xsd file.
* DataSetExamples - had to also correct byte != operator references by casting to int for these lines of code in TypedGroupOpenDefectSummariesByStatus.cs and TypedShowAllOpenDefectSummaries.cs:

where (int)defect.Status != (int)Status.Closed

* EntityFramework - deleted existing datasource and DefectModel.edmx file. Recreated them via new Entity Data Model datasource. Named it simply the SkeetysoftDefects.datasource and renamed the outputted Model1.edmx file to DefectModel.edmx.
* EntityFramework - changed following lines in ShowAllClosedDefects because of above changes and had left on the setting of "Pluarlize/Singularize" objects when creating above datasource:

using (var connection = new SkeetysoftDefects()) {
var query = from Defect defect in connection.Defects
jon.skeet (451) [Avatar] Offline
#8
Re: Sample code from the first edition?
Thanks for taking the type to document your steps. They'll be useful when I finally get round to porting that code when the final book is ready smilie
jdfagan (4) [Avatar] Offline
#9
Re: Sample code from the first edition?
> I'm not sure what's wrong with the DataSet examples -
> to be honest, those examples are removed from the
> second edition as I no longer use LINQ to DataSet.
> The same is true for the Entity Framework example.
> I'm happy to try to get both working, but it's likely
> to be after the second edition is released.
>
This may be well too late to make this suggestion...but I was thinking that since you will/may remove the DataSet example and/or the Entity Framework examples from 2nd edition, it would be cool for you to add an example of an OO database Linq implementation for the 2nd edition?

http://evain.net/blog/articles/2008/02/06/an-elegant-linq-to-db4o-provider-and-a-few-linq-tricks
http://www.db4o.com/

Db4o is an open source object database and could be compelling to consider if one is building new software and a new database from scratch without really having the need for a legacy relational database and/or the need to access such persisted data besides the software itself. I think it can be much faster performance from my initial looks into this technology..no impedance mismatch to consider since no relational persistence engine to deal with.

Alternatively if you discuss it in your blog after you get edition 2 released, I'd be happy to hear your opinion about it smilie.

Cheers,

JD
jon.skeet (451) [Avatar] Offline
#10
Re: Sample code from the first edition?
I'm afraid that not only is it too late, but I don't think there'd be room for it anyway. The new version of chapter 12 has been rewritten to try to show the flexibility of LINQ - it now covers:

- LINQ to SQL (just as an example of expression trees creating queries)
- LINQ to XML (building an API with LINQ in mind)
- Parallel LINQ (re-implementing LINQ to Objects for parallelism, effectively)
- Reactive Extensions (turning LINQ to Objects on its head)
- Adding your own LINQ operators to LINQ to Objects

It would be great to have room to explore all the different LINQ providers available, but there just isn't space smilie

Jon