首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#数据库的var如何用?

2012-04-23 
C#数据库的var怎么用??用wpf写的要连接数据库的程序,用的是DataGride,方法是 msdn 的这个 http://msdn.mic

C#数据库的var怎么用??
用wpf写的要连接数据库的程序,用的是DataGride,方法是 msdn 的这个 http://msdn.microsoft.com/zh-cn/library/ee340709.aspx
MSDN上给的代码如下:

C# code
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的这个要怎么弄。应该很简单吧,我是新手。求教了。。
先谢了~


[解决办法]
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();



热点排行