David Stone's Blog

I'm open to suggestions for a subtitle here! (Really!)

May LINQ CTP - Update Goodness

The new May LINQ CTP is out and it brings a slew of updates to the previous CTP. I, of course, grabbed it as soon as I could and installed it. I've been working on an XLinq article for CodeProject in between classes, midterms, school project, and work, so I popped open that solution in Visual Studio first. I noticed a few changes right away.

VB.NET Changes

One of the first things I noticed in my solution was that all my VB queries were completely broken. That's because this CTP comes with the changes to the VB.NET LINQ syntax that Paul Vick posted about a few days ago. I think this is a great thing as it enabled Intellisense in queries in a way that wasn't there before. Also, as I stated in the comments on Paul's blog:

...with XLinq being such a key piece of Linq for VB.NET (Obviously. I mean, you guys are including XML literals. That's got to mean something.), I would almost think you would have wanted to adopt the FLWOR style queries that XQuery has in the first place. It seems to me that would certainly make VB.NET a more attractive option for those who do a lot of work with XML.
As soon as I re-ordered the queries, they worked perfectly. And, what's more, I had nice Intellisense in these queries. A much welcome change.

C# Changes

Some of my C# queries were broken as well. Now, I might have missed this before, but everywhere I looked the way to do nested queries looked like this:

var entries = from log in EventLog.GetEventLogs(),

                   entry in (EventLogEntries)log.Entries

              where log.Log == eventLog

              select entry;


Now, as I said, I could be wrong. But that compiled and worked before. And that was all I could get to work. The new CTP introduces the join operator. But that's not really what I wanted. So I looked at the new nested query syntax in the SampleQueries samples and I reworked my query to look like this:

var entriesByCategory = from log in EventLog.GetEventLogs()

                        where log.Log == eventLog

                            from entry in (EventLogEntries)log.Entries

                            select categories;


Which is great! This is, to me, a much more natural way to query hierarchical data than the previous way. (If indeed I am correct in thinking that this wasn't the way to query data like this before.) (BTW, in case you were wondering, the EventLogEntries class is just a wrapper I wrote around EventLogEntryCollection because it doesn't implement IEnumerable<T>

ASP.NET Support

This CTP also introduces two things to integrated LINQ into ASP.NET apps. The first is an ASP.NET LINQ Application template under File|New|Website. This has references to System.Query and family and uses the experimental LINQ compiler. This will be useful for me as I can integrate my XLinq stuff into an IHttpHandler to return some RSS. Good stuff.

The second thing is a new DLinqDataSource provider. This provider acts just like the other DataSource classes. So you can hook up your data driven controls to DLinq queries rather than straight to the DataSet or whatnot.

Samples

There are a bunch of new sample applications in the /Samples directory. The SampleQueries application has been updated with the new standard query operators (Join, First, ElementAt, etc.) There are also a few databinding example applications. The WCFLinq app. 

One of  the applications that really intrigued me was the ExpressionTreeVisualizer addin for Visual Studio. With it, you can see what your Expression tree looks like in an intuitive sense. Hovering over the following:

Expression myExp = Expression.Add(

    Expression.Multiply(

        Expression.Constant(5),

        Expression.Constant(10)),

    Expression.Constant(20));

Gives me the normal debugger tooltip that shows me that I've got:
{Add(Multiply(5, 10), 20)}

Which, if you ask me, is pretty dang sweet in and of itself. But, using the debugger visualizer, I can see it in a tree view. And, since these are called Expression Trees, that seems kind of appropriate. Very nice work guys. This is good stuff.

Another of the sample applications that caught my eye was this LogicProgramming sample. There is some heady stuff in here that it's going to take me a while to wrap my arms around.

IQueryable<T>

This is the magic that makes DLinq happen. This converts your Expression Tree into SQL for you. And, theoretically, could convert your Expression Tree into...anything. I wouldn't do nearly as good of a job describing it as Matt Warren does here.

Anyway. Those are the things that caught my eye in this release. Good stuff to think about. Once I get done with that XLinq article, I'll start one on Expression Trees. There's a lot there.
Posted: May 10 2006, 06:14 PM by David Stone | with 7 comment(s)
Filed under:

Comments

Paul Watson said:

It is slew, not slieu. Slieu sounds French.

(Just getting back at you for the broccoli correction ;))
# May 11, 2006 3:15 AM

David Stone said:

Good catch, Paul. Didn't realize that. :-p
# May 11, 2006 3:19 AM

May LINQ CTP - Update Goodness said:

Pingback from  May LINQ CTP - Update Goodness

# November 28, 2007 6:24 AM

Webys said:

I have a little problem I'm a beginner in LINQ to SQL and I've follow the tutorial from ScottGu's blog: weblogs.asp.net/.../linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

All was ok I use VS 2008 (I've converted from VB.NET to C# , I use C#) but when I wish to put the code from App_Code in an sub dir like DAL or BLL (for extensibility of entities like products with partial clases) and generate again the dblm file I've receiving en error:

1. first in my BLL dir from App_Code:

  public partial class Product

   {

       partial void OnValidate(System.Data.Linq.ChangeAction action)

       {

           if (action == ChangeAction.Update && this.Discontinued == true && this.UnitsOnOrder > 0)

           {

               throw new ArgumentException("Record level can't be grather than 0 if Product is Discontinued");

           }

       }

}

and I've included the namespace : using DAL;

... but still error message is :No defining declaration found for implementing declaration of partial method 'Product.OnValidate(System.Data.Linq.ChangeAction)'

2  If i comment all BLL code from my extensibility partial class Product I receive an general error:

Could not load type 'NorthwindDataContext'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Could not load type 'NorthwindDataContext'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Could not load type 'NorthwindDataContext'.]

  System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +565

  System.Web.UI.WebControls.LinqDataSourceView.get_ContextType() +68

[InvalidOperationException: Could not find the type specified in the ContextTypeName property of LinqDataSource 'CategoryLinqDS'.]

  System.Web.UI.WebControls.LinqDataSourceView.get_ContextType() +193

  System.Web.UI.WebControls.LinqDataSourceView.CreateContextAndTable() +458

  System.Web.UI.WebControls.LinqDataSourceView.EnsureContextAndTable(Boolean selecting) +39

  System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +421

  System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +92

  System.Web.UI.WebControls.ListControl.PerformSelect() +31

  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70

  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82

  System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +26

  System.Web.UI.Control.PreRenderRecursiveInternal() +86

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

Thanks in advance guys. :)

# July 3, 2008 8:37 AM

weblogs.asp.net said:

446021.. Retweeted it :)

# March 30, 2011 12:07 AM

weblogs.asp.net said:

446021.. Reposted it :)

# April 26, 2011 5:41 PM

weblogs.asp.net said:

446021.. Corking :)

# June 9, 2011 4:56 PM