原本不支持 IQueryable 主要出于使用习惯的考虑,如果继承
IQueryable,编写代码的智能总会提示出现一堆你不想使用的方法(对不起,我有强迫症),IQueryable
自身提供了一堆没法实现的方法,还有外部入侵的扩展方法,严重影响编码体验。如下图:



原以为必须实现 IQueryable 才可以实现,结果一次惊喜,原来只要有对应的方法就成。

虽然支持了,但是还是推荐使用【链式 + lambda】 !!!

特别说明

这次功能更新,ISelect 增加了 5个方法,对【链式 + lambda】的用户可能会造成少许影响,我在注释上标明了,如下图:



特别是 .Select(),原先没有支持,该功能与 ToList(a => new Dto{}) 合并实现的。

需要避免一下坑:

*
如果一定要使用 .Select() 方法,请务必在 .ToList() 之前调用它;

*
请减少图中方法在【链式 + labmda】模式下的使用;

所有 ISelect 都可以使用 linq to sql,包括 Repository、DbContext;

Where
var t1 = ( from a in fsql.Select<Student>() where a.id == item.id select a
).ToList();
Select(指定字段)
var t1 = ( from a in fsql.Select<Student>() where a.id == item.id select new {
a.id } ).ToList();
CaseWhen
var t1 = ( from a in fsql.Select<Student>() where a.id == item.id select new {
a.id, a.name, testsub = new { time = a.age > 10 ? "大于" : "小于或等于" } } ).ToList();
Join
var t1 = ( from a in fsql.Select<Student>() join b in fsql.Select<School>() on
a.id equals b.StudentId select a ).ToList(); var t2 = ( from a in
fsql.Select<Student>() join b in fsql.Select<School>() on a.id equals
b.StudentId select new { a.id, bid = b.id } ).ToList(); var t3 = ( from a in
fsql.Select<Student>() join b in fsql.Select<School>() on a.id equals
b.StudentId where a.id == item.id select new { a.id, bid = b.id } ).ToList();
LeftJoin
var t1 = ( from a in fsql.Select<Student>() join b in fsql.Select<School>() on
a.id equals b.StudentId into temp from tc in temp.DefaultIfEmpty() select a
).ToList(); var t2 = ( from a in fsql.Select<Student>() join b in
fsql.Select<School>() on a.id equals b.StudentId into temp from tc in
temp.DefaultIfEmpty() select new { a.id, bid = tc.id } ).ToList(); var t3 = (
from a in fsql.Select<Student>() join b in fsql.Select<School>() on a.id equals
b.StudentId into temp from tc in temp.DefaultIfEmpty() where a.id == item.id
select new { a.id, bid = tc.id } ).ToList();
From(多表查询)
var t1 = ( from a in fsql.Select<Student>() from b in fsql.Select<School>()
where a.id == b.StudentId select a ).ToList(); var t2 = ( from a in
fsql.Select<Student>() from b in fsql.Select<School>() where a.id ==
b.StudentId select new { a.id, bid = b.id } ).ToList(); var t3 = ( from a in
fsql.Select<Student>() from b in fsql.Select<School>() where a.id ==
b.StudentId where a.id == item.id select new { a.id, bid = b.id } ).ToList();
GroupBy(分组)
var t1 = ( from a in fsql.Select<Student>() where a.id == item.id group a by
new {a.id, a.name } into g select new { g.Key.id, g.Key.name, cou = g.Count(),
avg = g.Avg(g.Value.age), sum = g.Sum(g.Value.age), max = g.Max(g.Value.age),
min = g.Min(g.Value.age) } ).ToList();
系列文章导航

*
(一)入门 <https://www.cnblogs.com/FreeSql/p/11531300.html>

*
(二)自动迁移实体 <https://www.cnblogs.com/FreeSql/p/11531301.html>

*
(三)实体特性 <https://www.cnblogs.com/FreeSql/p/11531302.html>

*
(四)实体特性 Fluent Api <https://www.cnblogs.com/FreeSql/p/11531304.html>

*
(五)插入数据 <https://www.cnblogs.com/FreeSql/p/11531306.html>

*
(六)批量插入数据 <https://www.cnblogs.com/FreeSql/p/11531309.html>

*
(七)插入数据时忽略列 <https://www.cnblogs.com/FreeSql/p/11531316.html>

*
(八)插入数据时指定列 <https://www.cnblogs.com/FreeSql/p/11531318.html>

*
(九)删除数据 <https://www.cnblogs.com/FreeSql/p/11531320.html>

*
(十)更新数据 <https://www.cnblogs.com/FreeSql/p/11531321.html>

*
(十一)更新数据 Where <https://www.cnblogs.com/FreeSql/p/11531324.html>

*
(十二)更新数据时指定列 <https://www.cnblogs.com/FreeSql/p/11531327.html>

*
(十三)更新数据时忽略列 <https://www.cnblogs.com/FreeSql/p/11531334.html>

*
(十四)批量更新数据 <https://www.cnblogs.com/FreeSql/p/11531335.html>

*
(十五)查询数据 <https://www.cnblogs.com/FreeSql/p/11531339.html>

*
(十六)分页查询 <https://www.cnblogs.com/FreeSql/p/11531341.html>

*
(十七)联表查询 <https://www.cnblogs.com/FreeSql/p/11531346.html>

*
(十八)导航属性 <https://www.cnblogs.com/FreeSql/p/11531352.html>

*
(十九)多表查询 <https://www.cnblogs.com/FreeSql/p/11531362.html>

*
(二十)多表查询 WhereCascade <https://www.cnblogs.com/FreeSql/p/11531372.html>

*
(二十一)查询返回数据 <https://www.cnblogs.com/FreeSql/p/11531376.html>

*
(二十二)Dto 映射查询 <https://www.cnblogs.com/FreeSql/p/11531381.html>

*
(二十三)分组、聚合 <https://www.cnblogs.com/FreeSql/p/11531384.html>

*
(二十四)Linq To Sql 语法使用介绍

*
(二十五)延时加载 <https://www.cnblogs.com/FreeSql/p/11531395.html>

*
(二十六)贪婪加载 Include、IncludeMany、Dto、ToList
<https://www.cnblogs.com/FreeSql/p/11531404.html>

*
(二十七)将已写好的 SQL 语句,与实体类映射进行二次查询
<https://www.cnblogs.com/FreeSql/p/11531416.html>

*
(二十八)事务 <https://www.cnblogs.com/FreeSql/p/11531423.html>

*
(二十九)Lambda 表达式 <https://www.cnblogs.com/FreeSql/p/11531425.html>

*
(三十)读写分离 <https://www.cnblogs.com/FreeSql/p/11531430.html>

*
(三十一)分区分表 <https://www.cnblogs.com/FreeSql/p/11531435.html>

*
(三十二)Aop <https://www.cnblogs.com/FreeSql/p/11531471.html>

*
(三十三)CodeFirst 类型映射 <https://www.cnblogs.com/FreeSql/p/11531543.html>

*
(三十四)CodeFirst 迁移说明 <https://www.cnblogs.com/FreeSql/p/11531550.html>

*
(三十五)CodeFirst 自定义特性 <https://www.cnblogs.com/FreeSql/p/11531576.html>