简体   繁体   中英

LinqDataSource Select syntax

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM