简体   繁体   English

LINQ查询出了什么问题

[英]What is wrong with this LINQ query

I have never done anything with LINQ before, however I have experience with MySQL. 我以前从未使用过LINQ,但是我有使用MySQL的经验。

I am on page 232 of Microsoft® ASP.NET 4 Step by Step and the book has started to talk about LINQ which is cool. 我在Microsoft®ASP.NET 4逐步指南的第232页上,这本书开始谈论LINQ,这很酷。

The book has instructed my to type my first LINQ query which I have, however it has resulted in 19 errors from Visual Studio, because the where , orderby and select commands are not recognised. 这本书指示我键入我的第一个LINQ查询,但是由于无法识别whereorderbyselect命令,因此导致Visual Studio出现19个错误。

Below is the code from the book: 以下是本书中的代码:

书号

Below is my code (in the form of a screenshot so you can see what Visual Studio doesn't like): 以下是我的代码(以屏幕截图的形式,您可以看到Visual Studio不喜欢的内容):

我的代码

What am I doing wrong? 我究竟做错了什么?

Thankyou 谢谢

In your Linq query, the TechnologyDescriptor tag wih the "<>" is barfing. 在您的Linq查询中,带有“ <>”的TechnologyDescriptor标记正在倒转。 What you need to do is specify a named variable instance for an individual item in the technologyDescriptor list. 您需要做的是在technologyDescriptor列表中为单个项目指定一个命名变量实例。 For example: 例如:

GridView1.DataSource = from td in technologyDescriptor where td.TechnologyName.Contains(".Net") == true order by td.TechologyName.Length
select td.TechnologyName.ToUpper();

You can think of this query as similar to a foreach loop that is looping over technologyDesciptor list and "td" being the individual record for each loop 您可以认为此查询类似于foreach循环,该循环遍历technologyDesciptor列表,而“ td”是每个循环的单独记录

您可能在TechnologyDescriptor周围没有多余的尖括号(<>)。

You have surrounded your variable name, technologyDescriptor, with angle brackets. 您已经用尖括号括住了变量名technologyDescriptor。 Please remove these brackets from your code. 请从代码中删除这些括号。

应该说:“来自...中的technologyDescriptor ”,而不是from <TechnologyDescriptor>

Your variable usage is a little off. 您的可变用法有点差。 Also, is technologyDescriptor a collection? 另外, technologyDescriptor是集合吗?

If so, change your code to: 如果是这样,请将您的代码更改为:

GridView1.DataSource = from t in technologyDescriptor
                       where t.TechnologyName.Contains(".NET")
                       orderby t.TechnologyName.Length
                       select t.TechnologyName.ToUpper();

In addition to the problems with your linq query, the screen shot shows that you have a variable scope problem. 除了linq查询的问题外,该屏幕快照还显示您还有可变范围的问题。 Specifically, you are using technologyDescriptor to refer to two different things. 具体来说,您正在使用technologyDescriptor来引用两个不同的事物。 Does your form have a control called "technologyDescriptor", or a field of that name declared in another part of the partial class? 您的表单中是否有一个名为“ technologyDescriptor”的控件,或者在分部类的另一部分中声明了该名称的字段?

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

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