日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/18 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FreeSql (二十四)Linq To Sql 语法使用介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原本不支持 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.idselect a ).ToList();

Select(指定字段)

var t1 = (from a in fsql.Select<Student>()where a.id == item.idselect new { a.id } ).ToList();

CaseWhen

var t1 = (from a in fsql.Select<Student>()where a.id == item.idselect 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.StudentIdselect a ).ToList();var t2 = (from a in fsql.Select<Student>()join b in fsql.Select<School>() on a.id equals b.StudentIdselect 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.StudentIdwhere a.id == item.idselect 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 tempfrom 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 tempfrom 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 tempfrom tc in temp.DefaultIfEmpty()where a.id == item.idselect 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.StudentIdselect a ).ToList();var t2 = (from a in fsql.Select<Student>()from b in fsql.Select<School>()where a.id == b.StudentIdselect 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.StudentIdwhere a.id == item.idselect new { a.id, bid = b.id } ).ToList();

GroupBy(分組)

var t1 = (from a in fsql.Select<Student>()where a.id == item.idgroup a by new {a.id, a.name } into gselect 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();

系列文章導航

  • (一)入門

  • (二)自動遷移實體

  • (三)實體特性

  • (四)實體特性 Fluent Api

  • (五)插入數據

  • (六)批量插入數據

  • (七)插入數據時忽略列

  • (八)插入數據時指定列

  • (九)刪除數據

  • (十)更新數據

  • (十一)更新數據 Where

  • (十二)更新數據時指定列

  • (十三)更新數據時忽略列

  • (十四)批量更新數據

  • (十五)查詢數據

  • (十六)分頁查詢

  • (十七)聯表查詢

  • (十八)導航屬性

  • (十九)多表查詢

  • (二十)多表查詢 WhereCascade

  • (二十一)查詢返回數據

  • (二十二)Dto 映射查詢

  • (二十三)分組、聚合

  • (二十四)Linq To Sql 語法使用介紹

  • (二十五)延時加載

  • (二十六)貪婪加載 Include、IncludeMany、Dto、ToList

  • (二十七)將已寫好的 SQL 語句,與實體類映射進行二次查詢

  • (二十八)事務

  • (二十九)Lambda 表達式

  • (三十)讀寫分離

  • (三十一)分區分表

  • (三十二)Aop

  • (三十三)CodeFirst 類型映射

  • (三十四)CodeFirst 遷移說明

  • (三十五)CodeFirst 自定義特性

轉載于:https://www.cnblogs.com/FreeSql/p/11531392.html

總結

以上是生活随笔為你收集整理的FreeSql (二十四)Linq To Sql 语法使用介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。