随笔分类 - LINQ
摘要:Group By/Having操作符适用场景:分组数据,为我们查找数据缩小范围。说明:分配并返回对传入参数进行分组操作后的可枚举对象。分组;延迟1.简单形式:var q = from p in db.Products group p by p.CategoryID into g select g;语句描述:使用Group By按CategoryID划分产品。说明:from p in db.Products 表示从表中将产品对象取出来。group p by p.CategoryID into g表示对p按CategoryID字段归类。其结果命名为g,一旦重新命名,p的作用域就结...
阅读全文
摘要:Union All/Union/Intersect操作适用场景:对两个集合的处理,例如追加、合并、取相同项、相交项等等。Concat(连接)说明:连接不同的集合,不会自动过滤相同项;延迟。1.简单形式:varq = (fromcindb.Customersselectc.Phone ).Concat(fromcindb.Customersselectc.Fax ).Concat(fromeindb.Employeesselecte.HomePhone );语句描述:返回所有消费者和雇员的电话和传真。2.复合形式:varq = (fromcindb.Customersselect new{ Na
阅读全文