Projecting in more details (single, multiple items, anonymous types)

One interesting aspect of VB queries is that you can select multiple values. When you do this, the values get combined into an anonymous type. “Anonymous types” is a new feature for VB9. Essentially an anonymous type is a class that contains one or more named values.  Compiler simply generates an anonymous type with number,…

0

Flattening a nested list using queries.

This seems to be a common question – ” I have a list of lists (or array or arrays), how can I flatten it into a single list/array? “ It is surprisingly trivial to do with queries. It takes one line of code – Module Module1     Sub Main()         ‘create a list of lists…

0

Adding more operators with Where as an example ( Query Design continued ):

This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/06/07/query-pattern-composability-query-design-continued.aspx   As you might have seen queries have a lot more operators than just Select. Here we will take a look how we can add support for Where to our queryable type.   It is surprisingly…

0

Delayed Execution ( Query Design continued ):

 This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/06/07/query-pattern-composability-query-design-continued.aspx   Here is another important example of a queryable type. There are two differences from the previous examples:   It uses System.Func delegate type that is defined in System.Core.dll . There is nothing special in using…

1

Scalar queryable example ( Query Design continued ):

  This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/06/08/generic-queryable-example-query-design-continued.aspx     Here is one more example of a queryable type. While weird and fairly useless it illustrates that queryable type does not have to be a collection. This one represents a single scalar value….

0

Generic queryable example ( Query Design continued ):

This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/06/07/query-pattern-composability-query-design-continued.aspx   Here is another example of a queryable collection. In this case we have a collection that is generic so it can be used with elements of different types. What is more interesting is that MyGenericQueryable…

1

Query pattern, Composability ( Query Design continued ):

  This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/02/19/polymorphic-selector-and-extension-methods-query-design-continued.aspx     Here I want to summarize what exactly the minimum requirements are for a type to be considered queryable with some explanations why we have such rules.   Quaryable type requirements: 1.       There must be…

3

Polymorphic selector and Extension methods ( Query Design continued ):

 This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/02/05/query-expression-query-design-continued.aspx   So far we have followed design decisions for the language integrated queries to the point where user specifies the query in the following form.   Dim num_squares = From cur_num In numbers Select result =…

1

Query expression ( Query Design continued ):

This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/01/30/representing-the-user-code-by-delegates-query-design-continued.aspx   In the previous posts we have designed a very handy function that can iterate any IEnumerable(of T) and apply given expression to all elements, but the disadvantages are obvious – more code to type. We tried…

6

Representing the user code by delegates ( Query Design continued ):

         This post is a part of a series of posts about query design. For the previous post see: http://blogs.msdn.com/vladimirsadov/archive/2007/01/22/generic-implementation-of-iterateandapply-query-design-continued.aspx    Lets’ now consider the implementation of Apply function. In theory we could somehow interpret the string inside the Apply function, but having code in a form of string still causes problems. Consider the following…

1