Linq GroupJoin 使用
备忘:
var data = BoshccEntities.Current.TB_MB_1
.GroupJoin(BoshccEntities.Current.TB_MB_2, o => o.HospitalID, m => m.MemberID, (t, m) => new { t, m })
.GroupJoin(BoshccEntities.Current.TB_CM_3, o => o.t.ServiceCode, s => s.DicNum, (o, s) => new { t = o.t, m = o.m, s })
.GroupJoin(BoshccEntities.Current.TB_CM_3, o => o.t.PaymentMethodCode, p => p.DicNum, (o, p) => new { t = o.t, m = o.m, s = o.s, p })
.Where(o =>
(isenable.HasValue ? o.t.IsEnable == isenable.Value : true)
&& (hasHospital ? hospitalIDs.Contains(o.t.HospitalID) : true)
&& (hasService ? o.t.ServiceCode == service : true)
&& (hasPayment ? o.t.PaymentMethodCode == payment : true))
.OrderBy(o => o.t.ID)
.Select(o => new
{
ID = o.t.ID,
HospitalID = o.t.HospitalID,
ServiceCode = o.t.ServiceCode,
PaymentMethodCode = o.t.PaymentMethodCode,
IsEnable = o.t.IsEnable,
Remark = o.t.Remark, Hospital = o.m.FirstOrDefault(), //关键1
Service = o.s.FirstOrDefault(),
Payment = o.p.FirstOrDefault()
})
.ToList() //关键2
.Select(o => new TB_MB_4
{
ID = o.ID,
HospitalID = o.HospitalID,
ServiceCode = o.ServiceCode,
PaymentMethodCode = o.PaymentMethodCode,
IsEnable = o.IsEnable,
Remark = o.Remark, HospitalName = o.Hospital == null ? "" : o.Hospital.HospitalName, //关键3
ServiceName = o.Service == null ? "" : o.Service.DicName,
PaymentName = o.Payment == null ? "" : o.Payment.DicName
});
Linq GroupJoin 使用的更多相关文章
- Linq GroupJoin
static void Main(string[] args) { List<Person> persons = new List<Person> { }, }, }; Lis ...
- Linq GroupJoin , Join
static void Main(string[] args) { List<Person> persons = new List<Person> { }, }, }; Lis ...
- LINQ查询操作符之Select、Where、OrderBy、OrderByDescending、GroupBy、Join、GroupJoin及其对应的查询语法
介绍 ·Select - Select选择:延迟 ·Where - Where查询:延迟 ·OrderBy - 按指定表达式对集合正序排序:延迟 ·OrderByDescend ...
- LINQ标准查询操作符(二)——Join、GroupJoin、GroupBy、Concat、
四.联接操作符 联接是指将一个数据源对象与另一个数据源对象进行关联或者联合的操作.这两个数据源对象通过一个共同的值或者属性进行关联. LINQ有两个联接操作符:Join和GroupJoin. 1. J ...
- [C#] LINQ之Join与GroupJoin
声明:本文为www.cnc6.cn原创,转载时请注明出处,谢谢! 一.编写Person与City类,如下: class Person { public int CityID { set; get; } ...
- Linq分组操作之GroupBy,GroupJoin扩展方法源码分析
Linq分组操作之GroupBy,GroupJoin扩展方法源码分析 一. GroupBy 解释: 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值. 查询表达式: var ...
- LINQ之 Join 与 GroupJoin
声明:本文为www.cnc6.cn原创,转载时请注明出处,谢谢! 一.编写Person与City类,如下: class Person { public int CityID { set; get; } ...
- [C#] LINQ之SelectMany和GroupJoin
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Linq in GroupBy GroupJoin
还是上一份的代码例子: public class Person { public int ID { get; set; } public string Name { get; set; } publi ...
随机推荐
- HTML与CSS入门——第八章 使用外部和内部链接
知识点: 1.链接锚的使用方法 2.在自己的网站上的页面之间链接的方法 3.链接到外部内容的方法 4.链接到一个E-mail地址的方法 5.在新浏览器窗口中查看链接的方法 6.用CSS为链接添加样式的 ...
- asp.net事件委托易理解实例
比如说一个公司(场景),你是老板,手下有两个员工,小张和小王. 你命令小王,如果小张玩游戏,则小王扣去小张500元钱.这就是现实中的委托.实际上,在写程序中,程序员就是老板,小张和小王就是两个对象.小 ...
- 使用DataReader
string sqlStr="select * from tb_news"; SqlCommand myCmd=new SqlCommand(sqlStr,myConn); myC ...
- cocos2dx Menu
---恢复内容开始--- cocos2dx 3.0以后 Menu相关回调函数使用不同.现在列出当前版本可使用的方法. 看见一个说的很仔细的博客,博客源地址 http://blog.sina.com.c ...
- VC 串口通信类
为了节省时间,我就贴出来吧 头文件 SerialPort.h /******************************************************************** ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- Linux-统一事件源
概念: 信号时一种异步事件:信号处理函数和程序的主循环式两条不同的执行路线,信号处理函数需要尽可能快地执行完毕,以确保该信号不被屏蔽.(为了避免一些竞态条件,信号在处理期间,系统不会再次出发它)太久. ...
- javascript中定义事件的三种方式
在javascript中,可以为某个元素指定事件,指定的方式有以下三种: 1.在html中,使用onclick属性 2.在javascript中,使用onclick属性 3.在javascipt中,使 ...
- Python入门学习之input()与raw_input()的区别
登陆博客时才发现已经注册一年了,由于之前一直都没有打算从事软件开发行业,所以博客便被束之高阁,软件开发,对于我来说,是成长,更是磨炼.头脑风暴总是来去自由,记录灵感,与大家一起共享思维进步的成果. P ...
- sqlserver exists和in 与exists和not in
1.exists 和 in 1.1 正常情况下exists和in的效果是一样的,如图试验 即使子查询中包含null也没有关系,依然可以正常使用 1.2 in 和 exists效率比较 先看in 由图中 ...