1.左右链接
//此处相当于left join 左连接查询 左右链接替换主从就行了
var query = db.CRM_BIGDATA.GroupJoin(db.CRM_BIGDATA_EMAIL_REF, (CRM_BIGDATA x) => x.RID, (CRM_BIGDATA_EMAIL_REF y)=>Convert.ToInt32(y.BIG_DATA_ID), (x, list) => new { x, list });
//左连接
var resultLeft = from s in db.CRM_BIGDATA
join x in db.CRM_BIGDATA_EMAIL_REF
on s.RID equals Convert.ToInt32(x.BIG_DATA_ID) into empy
from x in empy.DefaultIfEmpty()
select new { s, x };
//右链接
var resultReight = from s in db.CRM_BIGDATA_EMAIL_REF
join x in db.CRM_BIGDATA
on s.RID equals Convert.ToInt32(x.BIGDATAID) into empy
from x in empy.DefaultIfEmpty()
select new { s, x };
2.分组查询
var queryLambdaGroup = db.CRM_BIGDATA.GroupBy(x => x.KEYWORD).ToList();
var queryLinqGroup = from u in db.CRM_BIGDATA group u by u.KEYWORD into g select g;
3.升降序
//将序 升序排法
var quLamOrder = db.CRM_BIGDATA.GroupBy(s=>s.KEYWORD).OrderBy(x => x.Key).OrderByDescending(y=>y.Key).ToList();
var quLinqOrder = from u in db.CRM_BIGDATA group u by u.KEYWORD into g orderby g.Key descending select g;
4.内链接查询
var quLamJoin = db.CRM_BIGDATA.Join(db.CRM_BIGDATA_EMAIL_REF, (CRM_BIGDATA x) => x.RID, (CRM_BIGDATA_EMAIL_REF y) => Convert.ToInt32(y.BIG_DATA_ID), (x, y) => new { x, y });
5.let 用法
var quLinqLet = from u in db.CRM_BIGDATA let length = u.KEYWORD.Length select new { len = length, u };
6.介绍工具
<1>LinqPad: 官方下载: http://www.linqpad.net/
具体用法:http://www.cnblogs.com/AlexLiu/archive/2008/10/24/1318998.html
使用说明: 可以生成其LINQ查询对应的lambda和SQL语句
<2>Linqer : 官方下载:http://www.sqltolinq.com/
具体用法:http://www.cnblogs.com/huangxincheng/archive/2011/05/12/2044990.html
使用说明: SQL语句转Linq