为什么我不能在这种情况下使用 var ?
我正在使用下面的代码,由于某种原因我无法使用 var 来声明我的变量。我是 ASP/C# 的新手,所以请对我宽容一些。我环顾四周,找不到正确的方法:
var brandslist = from brand in brandDB.brands
join brand_family in brandDB.brand_family on brand.brand_family_id equals brand_family.bf_id
orderby brand_family.brand_family_name
orderby brand.priority
orderby brand.genre_id
select brand_family.brand_family_name, priority, roll_image;
感谢任何可以告诉我完成这项工作的正确方法的人。
I am using the code below and for some reason I can't use var to declare my variable. I am brand new to asp/c# so please go easy on me. I've had a look around and I can't find the correct way of doing this:
var brandslist = from brand in brandDB.brands
join brand_family in brandDB.brand_family on brand.brand_family_id equals brand_family.bf_id
orderby brand_family.brand_family_name
orderby brand.priority
orderby brand.genre_id
select brand_family.brand_family_name, priority, roll_image;
Thanks to anyone who can tell me the correct method of making this work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果它是局部变量并且查询本身有效,那么您就可以。
但是,查询表达式无效。看看最后一行,这:
可能应该是:
值得仔细查看编译器错误 - 它通常对错误给出了相当好的解释。
接下来,你的顺序几乎肯定是错误的——我非常怀疑这是否达到了你想要的效果。要表达多个排序,您通常只需列出它们,并用逗号分隔,如下所示:
这将转换为
OrderBy
调用,后跟后续的ThenBy
调用 - 处理brand_family_name
作为主要排序顺序,其他作为次要排序。If it's a local variable and the query itself were valid, you would be able to.
However, the query expression is invalid. Just looking at the last line, this:
should probably be:
It's worth looking closely at the compiler error - it generally gives a reasonably good explanation of what's wrong.
Next up, your ordering is almost certainly wrong - I very much doubt that this does what you want it to. To express multiple orderings, you typically just list them, separated by commas, like this:
This will translate to an
OrderBy
call followed by subsequentThenBy
calls - treatingbrand_family_name
as the primary sort ordering, and the others as secondary orderings.固定:D
Fixed :D
var 公开枚举器,它支持对指定类型的集合进行简单迭代。在你选择brand_family.brand_family_name,priority,roll_image;
您要退回多件商品。
var exposes the enumerator, which supports a simple iteration over a collection of a specified type. In your select brand_family.brand_family_name, priority, roll_image;
you are returning multiple items.
不确定它是否会修复它,但试试这个:
Not sure if it will fix it but try this:
您还应该修复您的 orderby ,否则您只是重新排序
应该变成
orderbybrand_family.brand_family_name,brand.priority,brand.genre_id
You should also fix your orderby or else you are just reordering
Should become
orderby brand_family.brand_family_name, brand.priority, brand.genre_id