简体   繁体   English

LinqDataSource选择语法

[英]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#? 为什么LinqDataSource中Select属性的语法与Linq如此不同,我会用C#内联? I mean like: 我的意思是:

new (Id As MyId, Name As MyName)

vs 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. 我曾期望有一个名为LinqDataSource的东西可以让您提供一个已编译的Linq查询并完成它。

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. 另外,除了最简单的为字段加上别名的情况以外,我没有找到关于Select属性的语法的文档。 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. Linq Concat命令不起作用,碰巧我发现一个博客找到了一个替代方案。 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. 我认为这是因为as关键字在语言中已经具有不同的含义。 The chosen syntax resembles the syntax of default parameters (.net 4.0 following) and is pretty clear IMHO. 选择的语法类似于默认参数的语法(以下是.net 4.0),并且非常清楚恕我直言。

Note that this explicit syntax is only necessary when a property name for an anonymous type cannot be inferred or is ambigous. 请注意,仅当无法推断匿名类型的属性名称或该属性名称不明确时,才需要使用此显式语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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