Lambdas, and Take While, and Group By, Oh My!

Lambdas, and Take While, and Group By, Oh My!

  • Comments 4

Hooray! Visual Basic 2008 Beta2 has been released to the wild today to return to its natural habitat – the desktops of our beloved customers. (Please note our smiling GPM's face on that landing page -- he's so happy the Beta is done.)

What’s inside? So much that there might be more new features than we released in Beta1, but who’s counting? Here’s a laundry list that’s specific to the VB language that’s new for Beta2:

·         Query operators

o   Group By, Group Join, Join, Take [While], Skip [While], Aggregate, Count, Sum, Min, Max, Average, From à Let

·         Nullable support

·         Lambda Expressions (aka Inline Functions)

·         Partial Methods – ScottGu mentioned this the other day & ScottWis posted a couple weeks back

·         Anonymous Types w/Keys – Which PaulV has already discussed

Here are a bunch of queries you can now write with VB!

' Find suppliers in the same city as customers

From cust In db.Customers _

Join sup In db.Suppliers _

On cust.City Equals sup.City _

Select cust.CompanyName, sup.ContactName, cust.City

 

' Find suppliers in the same city, with the same postalcode as customers

From cust In db.Customers _

Join sup In db.Suppliers _

On cust.City Equals sup.City And cust.PostalCode Equals sup.PostalCode

Select cust.CompanyName, sup.ContactName, cust.City

' Find the average unit price and count for products by category

From prod In db.Products _

Group By prod.CategoryID _

Into Average(prod.UnitPrice), Count()

 

' For each customer find the group of the suppliers in the same country

From cust In db.Customers _

Group Join sup In db.Suppliers _

On cust.Country Equals sup.Country _

Into SuppliersInCountry = Group _

Select cust.CompanyName, SuppliersInCountry

' For each customer, the count of the number of suppliers in the same country

From cust In db.Customers _

Group Join sup In db.Suppliers _

On cust.Country Equals sup.Country _

Into NumSuppliers = Count() _

Select cust.CompanyName, NumSuppliers

 

' Avg price, avg # in stock, and max on order for non-discontinued products

Aggregate prod In db.Products _

Where Not prod.Discontinued _

Into AvgPrice = Average(prod.UnitPrice), _

     AvgInStock = Average(prod.UnitsInStock), _

     MaxOnOrder = Max(prod.UnitsOnOrder)

' Find orderID, OrderDate, and OrderTotal for each order

From order In db.Orders _

Where order.OrderDate > #7/22/1996# _

Aggregate ordDet In order.Order_Details _

Into OrderTotal = _

       Sum(ordDet.UnitPrice *ordDet.Quantity * (1 - ordDet.Discount))

Select order.OrderID, order.OrderDate, OrderTotal

 

' Fill a dictionary with the customers by CompanyName

db.Customers.ToDictionary(Function(cust As Customer) cust.CompanyName)

 

In addition to all the new language support, we now have keyword Intellisense (finally!)

Keyword Intellisense

We have XML Intellisense! What?? That’s right.

XML Intellisense

And we’ve done some major performance improvements for the background compiler – let us know if you experience any sluggishness for this Beta.  (BTW, you should check out Scott's post on Beta2 to avoid some problems with AJAX extensions if you're installing to a machine that has had previous versions of Orcas installed on it or has VS 2005 side by side.)

Also, don’t forget to look for other exciting features around the product that pertain to VB and/or LINQ. For example, Linq to SQL now supports the Like operator! There’s also a new ASP:LinqDataSource control.

 

So, get the bits while they’re hot!

 

-Amanda

Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
  • PingBack from http://www.universityupdate.com/Technology/Visual-Basic/4139446.aspx

  • Wow!

    I see lot's of new features. Even new more pastel-like coloring scheme.

    I also see the new Class constraint keyword.

    Speed is much better. "Initializing toolbox for 20 minutes"  bug is gone. Local MSDN  help started to work.

    Migrating...

    Had to manually cahange version of System.Web.Extentions many times inside web.config.

    GetChangeText is gone. Don't know where.

    Bad things: XML literals are now disabled in aspx files.

  • Are Automatic Properties coming to VB? I just started the beta 2 VS 2008 and it looks like they only work in C#. Aaaaahhh! Otherwise, I love some of the new features. Especially being able to use the new interface but target .Net 2.0.

    Cheers,

    Aaron

  • Our team uses VB.Net almost exclusively for developing agent and customer self-service applications for a major Canadian telecommunications company.  I say almost, because we still have to use C# to compensate for weaknesses in VB.Net.  Specifically: iterators and yield.  Can someone on the VB Team explain why these fundamental language capabilities, frequently requested by the community, don't seem to be important enough to Microsoft to target in the feature set?

Page 1 of 1 (4 items)