C#数据库的var怎么用??

HyanCat 2012-04-21 11:14:55
用wpf写的要连接数据库的程序,用的是DataGride,方法是 msdn 的这个 http://msdn.microsoft.com/zh-cn/library/ee340709.aspx
MSDN上给的代码如下:
ObjectQuery<Product> products = dataEntities.Products;

var query =
from product in products
where product.Color == "Red"
orderby product.ListPrice
select new { product.Name, product.Color, CategoryName = product.ProductCategory.Name, product.ListPrice };

dataGrid1.ItemsSource = query.ToList();


这个 var 的语句不太会用。我想要在 where 里面用个逻辑运算 or,可直接在上面的 where 后面写不行啊。不知道var的这个要怎么弄。应该很简单吧,我是新手。求教了。。
先谢了~
...全文
122 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2012-04-21
  • 打赏
  • 举报
回复
哦,给你搞迷糊了。不过你应该用 ||
HyanCat 2012-04-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

ObjectQuery<Product> products = dataEntities.Products;

var query =
from product in products
where product.Color == "Red" or product.Color == "Blue"
……
[/Quote]

1楼不行啊。我说了直接 where 后面加 or 不行。。根本没or这个关键字。
然后、、、我把 or 改成或运算符 | 居然就OK 了。。。。。。。
threenewbee 2012-04-21
  • 打赏
  • 举报
回复
ObjectQuery<Product> products = dataEntities.Products;

var query =
from product in products
where product.Color == "Red" or product.Color == "Blue"
orderby product.ListPrice
select new { product.Name, product.Color, CategoryName = product.ProductCategory.Name, product.ListPrice };

dataGrid1.ItemsSource = query.ToList();



111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧