日期:2014-05-18  浏览次数:20917 次

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();