tags:

views:

295

answers:

1

Why is it the syntax of the Select property in the LinqDataSource so different from Linq I would write inline in C#? I mean like:

new (Id As MyId, Name As MyName)

vs

new (MyId = Id, MyName = Name)

And the syntax diverges more when you start doing things like concatenation in the projection. I am using this with a Entity Data model as the provider, if that has anything to do with it.

I would have expected something called a LinqDataSource would simply allow you to supply a compiled Linq query and be done with it.

Also I could find no documentation on the syntax of what is expected for the Select property other than the most simple cases of aliasing the fields. The Linq Concat command doesn't work, and it was only a stroke of luck that I found a blog where someone figured out an alternative. So in the future when trying to do any other manipulations I pretty much can only take wild guesses in the dark.

+1  A: 

I think it is because the as keyword has already a different meaning in the language. The chosen syntax resembles the syntax of default parameters (.net 4.0 following) and is pretty clear IMHO.

Note that this explicit syntax is only necessary when a property name for an anonymous type cannot be inferred or is ambigous.

Johannes Rudolph
It's pretty clear when you read it, but when you go to construct your own query using standard LINQ operators and the LinqDataSource doesn't understand them, then the divergence becomes a problem. It becomes a guessing game. Where is the syntax that the LinqDataSource uses documented? Is this the VB syntax of LINQ?
AaronLS
What exactly is your question then?
Johannes Rudolph
It's the first question at the top of my post. Let me rephrase it like this, why doesn't this work in a LinqDataSource:"new ( Name = (FirstName + " " + LastName), EmployeeID)"And like I asked in the comment, where is the LinqDataSource flavor of Linq documented? Is it using a VB syntax of LINQ?
AaronLS