quick fix for Beta 2 VB sample problems

Posted Sun, Jul 29 2007 23:55 by bill

If you've installed the Beta 2 samples for VB Orcas 2008, then you will likely find the solutions don't open.  Problem is they are marked as being for "Orcas" not "2008".  This quick and dirty code will fix the problem:

 

With My.Computer.FileSystem

   Dim samplesPath = .SpecialDirectories.MyDocuments & "\VB Samples Beta2"

   For Each file In .GetFiles(samplesPath, FileIO.SearchOption.SearchAllSubDirectories, "*.sln")
      Dim contents = .ReadAllText(file)
      contents = contents.Replace("# Visual Studio Codename Orcas", "# Visual Studio 2008")
      .WriteAllText(file, contents, False)
   Next

End With

Filed under: , , ,

Comments

# LINQ to Sql changes from Beta 1 to Beta 2

Sunday, July 29, 2007 8:22 PM by Wooley's Wonderings

I've been working this weekend trying to get my samples for the upcoming Linq In Action book and other...

# LINQ to Sql changes from Beta 1 to Beta 2

Monday, July 30, 2007 9:29 AM by Wooley's LINQ Wonderings

I've been working this weekend trying to get my samples for the upcoming Linq In Action book and other

# re: quick fix for Beta 2 VB sample problems

Tuesday, July 31, 2007 9:58 AM by Roger Jennings

Hi, Bill,

A bit off topic, but I found that 'Into identifier = Group' compiles for Group Join and Group By but the Group By implementation throws a runtime error regarding a type conflict. See updates to oakleafblog.blogspot.com/.../strange-change-to-vb-join-and-group-by.html for details.

--rj

# re: quick fix for Beta 2 VB sample problems

Tuesday, July 31, 2007 1:12 PM by Roger Jennings

Hi, Bill,

Yes, your sample code ran fine in 'Sample Queries.' The problem was that I reused the Query## variable in both cases. Here's the Group Join example that compiles and runs correctly:

Dim Query11 = From c In CustomerList _

             Where c.Country = "USA" _

             Group Join o In OrderList _

             On c.CustomerID Equals o.CustomerID Into Group _

             From d In Group.DefaultIfEmpty(EmptyOrder) _

             Select New With {c, d}

'Alternative Into identifier = Group syntax

Query11 = From c In CustomerList _

         Where c.Country = "USA" _

         Group Join o In OrderList _

         On c.CustomerID Equals o.CustomerID Into co = Group _

         From d In co.DefaultIfEmpty(EmptyOrder) _

         Select New With {c, d}

Here's what I did for the Group By test:

Dim Query16 = From c In CustomerList _

             Order By c.Country, c.CustomerID _

             Group c By c.Country Into Group _

             Select Country, Group 'Optional

'Following throws a runtime error

Query16 = From c In CustomerList _

         Order By c.Country, c.CustomerID _

         Group c By c.Country Into g = Group _

         Select New With {Country, g} 'Not optional

In the Group By case, the data type differs between the implementations because both don't use New With.

Assigning a new variable for the second version solved the problem. I'm correcting the post now.

I do prefer your 'Group c By cntry = c.Country Into g = Group' syntax, so am adding it as a third option.

Thanks much for your help.

--rj

# re: quick fix for Beta 2 VB sample problems

Tuesday, July 31, 2007 1:26 PM by bill

yes the difference is the New With{ ...} syntax will create a mutable anonymous type wehreas the impied Select, or simple Select specifying just the properties, creates an immutable anonymous type.