Csharp/C#教程:将带有join的SQL查询转换为lambda表达式分享


将带有join的SQL查询转换为lambda表达式

不知道如何将以下sql转换为lambda表达式。 我的数据库使用参照完整性和与Content_Training表相关的表内容,具有1对多的关系(1个内容可以包含许多content_trainings)

select c.ContentId, c.Name, ct.TrainingTypeId from dbo.Content c left join dbo.Content_Training ct on c.ContentId = ct.ContentId where c.PublishDate is not null order by ct.TrainingTypeId, c.Name 

试试这个查询:

上述就是C#学习教程:将带有join的SQL查询转换为lambda表达式分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 var results = (from c in dbcontext.Contents join ct in dbcontext.Content_Trainings on c.ContentId equals ct.ContentId into t from rt in t.DefaultIfEmpty() select new { c.ContentId, c.Name, TrainingTypeId = (int?)rt.TrainingTypeId }).OrderBy(r => r.TrainingTypeId) .ThenBy(r => r.Name); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/956415.html

(0)
上一篇 2021年11月20日
下一篇 2021年11月20日

精彩推荐