Linq中的group by多表多字段
在sql中,如果有group by,那么select的字段只能包含分组内容,或者count、sum、avg这些统计字段。
但在linq里面,是:group 你想要什么字段 by 分组字段
比如:
var q =
from p in db.Products
group p by p.CategoryID into g
select g;
实际应用中,多表多字段参与分组比较常见:
from a in TableA
join b in TableB on a.Id equals b.aId
where ((b.Type == || b.Type == || b.Type == ) && b.State == )
group new { a.Id, b.Name,b,CreateDate } by new { a.Id, b.Name } into g
select (new Class1 { Id = g.Key.Id, Name = g.Key.Name ?? "" }); class Class1
{
public int Id { get; set; }
publid string Name { get; set; }
Linq中的group by多表多字段的更多相关文章
- Linq中的group by多表多字段,Sum求和
//Line to Sql 写法 var data = (from a in Items group a by new { a.GroupId, a.Id } into b //orderby new ...
- Linq中join & group join & left join 的用法
Linq中join & group join & left join 的用法 2013-01-30 11:12 12154人阅读 评论(0) 收藏 举报 分类: C#(14) 文章 ...
- sql 查找数据库中某字符串所在的表及字段
declare @str varchar(100) set @str='是否严格控制' --要搜索的字符串 declare @s varchar(8 ...
- linq中的group by
现有如下需求,要求统计int数组中每个整数的个数: ,,,,,,,,,,,, }; var linq = from item in arrInt group item by item into g// ...
- Linq中left join之多表查询
using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...
- hive中sql解析出对应表和字段的实现
import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map ...
- ecshop中user.php中的$user说明---user表加字段
今天想对user表加个字段,打开user.php发现有个$user,其中它有很多方法,像登陆,注册,退出.都要用到它.可找了大半天也找不到这个函数调用的是哪个类.又坚持找了半天,发现$user在ini ...
- hive中sql解析出对应表和字段的调查
---恢复内容开始--- .阿里的druid中的sql parser有各种关系数据库sql的解析,但hive的不支持. druid初期的版本中是包含hive的,将以前版本中的hive dialect对 ...
- Oracle中V$SESSION等各表的字段解释,Oracle官方解释
一.常用的视图 1.会话相关视图 View Description V$PROCESS Contains information about the currently active processe ...
随机推荐
- C++ sort使用自定义函数的一些坑
先看代码: 解释:使用自定义比较函数时,如果用了返回值恒为$true$或者恒为$false$的比较函数,就会这样子. 原因: https://stackoverflow.com/questions/4 ...
- 通过日志查看Web Api详细运行过程
1. 通过Nuget安装System.Web.Http.Tracing. 2. 通过HttpConfiguration,注册SystemDiagnosticsTraceWriter public st ...
- bom知识点
1.BOM输出 所谓BOM指的是浏览器对象模型 Browser Object Model,它的核心就是浏览器 alert(1);//弹出框 调式使用 console.log('路飞学城');//用于浏 ...
- [nginx]lua操作redis
local redis = require "resty.redis" local red = redis:new() red:set_timeout() -- sec -- or ...
- http中的Content-Type
要学习content-type,必须事先知道它到底是什么,是干什么用的. HTTP协议(RFC2616)采用了请求/响应模型.客户端向服务器发送一个请求,请求头包含请求的方法.URI.协议版本.以及包 ...
- django2.0新增功能流程
1先在 models.py中,创建字段相关的内容,我这里添加一个博客分类的表 定义数据结构的地方 class PostType(models.Model): title = models.CharFi ...
- Rhythmk 学习 Hibernate 08 - Hibernate annotation 关联关系注解
1.一对一 (One to One) 共三种情况: 1.1 主键共享 1.2 外键共享 1.3 中间表关联 1.1 code: @Entity public class arti ...
- leetcode225
public class MyStack { Queue<int> Q = new Queue<int>(); /** Initialize your data structu ...
- delphi 组件容器TObjectList代替List
delphi 组件容器TObjectList代替List TObjectList objList->delete(0); 这个会释放第0行元素的对象 class TTabFormInfo { p ...
- Discuz 任务、道具、任务和验证类插件制作
一.广告类脚本位置:source/class/adv/adv_name.php语言包位置:source/language/adv/lang_name.php <?php class adv_na ...