left join

            var custs = from c in db.T_Customer
join u in db.Sys_User on c.OwnerId equals u.Id into temp
from t in temp.DefaultIfEmpty() //left join
where (c.PhoneNum1 == phone || c.PhoneNum2 == phone || c.PhoneNum3 == phone)
select new
{
CustName = string.IsNullOrEmpty(c.CustName) ? "匿名" : c.CustName,
UserName = t == null ? "暂无" : t.Name//这里主要第二个集合有可能为空。需要判断
};

Linq中的left join的更多相关文章

  1. Linq 中的 left join

    Linq 中的 left join 表A User: 表B UserType: Linq: from t in UserType join u in User on t.typeId equal u. ...

  2. Linq中使用Left Join

    use Test Create table Student( ID ,) primary key, ) not null ) Create Table Book( ID ,) primary key, ...

  3. Linq中的连接(join)

    http://www.cnblogs.com/scottckt/archive/2010/08/11/1797716.html Linq中连接主要有组连接.内连接.左外连接.交叉连接四种.各个用法如下 ...

  4. LINQ中的连接(join)用法示例

    Linq中连接主要有组连接.内连接.左外连接.交叉连接四种.各个用法如下. 1. 组连接 组连接是与分组查询是一样的.即根据分组得到结果. 如下例,根据publisther分组得到结果. 使用组连接的 ...

  5. [转]Linq中使用Left Join

    本文转自:http://www.cnblogs.com/xinjian/archive/2010/11/17/1879959.html use Test Create table Student( I ...

  6. Linq中使用Left Join rught join

    准备一些测试数据,如下: use Test Create table Student( ID int identity(1,1) primary key, [Name] nvarchar(50) no ...

  7. Linq中使用Left Join 和 Right Join

    原文地址:http://www.cnblogs.com/xinjian/archive/2010/11/17/1879959.html 准备一些测试数据,如下: use Test Create tab ...

  8. linq中如何在join中指定多个条件

    public ActionResult Edit(int id) { using (DataContext db = new DataContext(ConfigurationManager.Conn ...

  9. Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式

    当前有两个表,sgroup与sgroupuser,两者通过gKey关联,而sgroup表记录的是组,而sgroupuser记录是组中的用户,因此在sgroupuser中不一定有数据.需要使用Left ...

随机推荐

  1. Java 存储时间戳的几种方式

    有时需要记录一下数据生成时间的时间戳,精确到秒,这里记录一下java存储时间戳字符串的几种方式 1.DateFormat private static final SimpleDateFormat s ...

  2. Linux批量修改(删除)文件名某些字符(rename命令)

    假设在路径C:/下存在多个类似以下的文件名 file_nall_abc1.txt file_nall_abc2.txt file_nall_abc3.txt file_nall_abc4.txt fi ...

  3. win10开机自启动

    快捷方式复制到win+ R 编辑shell:startup enter后的文件夹中

  4. 第十五节,卷积神经网络之AlexNet网络详解(五)

    原文 ImageNet Classification with Deep ConvolutionalNeural Networks 下载地址:http://papers.nips.cc/paper/4 ...

  5. 【清北学堂2018-刷题冲刺】Contest 6

    Task 1:子集 [问题描述]  若一个集合S中任意两个元素x和y,都满足x⊕y<min⁡(x, y) ,则称集合S是"好的".其中⊕为按位异或运算符.现在给定一个大小为n ...

  6. JSON与XML之间的转换

    public class JsonTest { private final Logger cLogger = Logger.getLogger(getClass()); /** * XML转JSON ...

  7. weblogic优化(内存、线程数和启动速度)

    一.为服务分配内存 1.一般如果服务所需的内存不一样,需要单独指定的话,我们是通过拷贝startWebLogic.sh文件,拷贝为startNode.sh(名字随意) 2.然后在startNode.s ...

  8. linux下使用sftp【转】

    . 本文完全引用自: http://www.cnblogs.com/kaituorensheng/p/5797753.html 何为sftp sftp是Secure File Transfer Pro ...

  9. C# 一个特别不错的http请求类

    using System; using System.Collections; using System.Collections.Generic; using System.Collections.S ...

  10. Java Service Wrapper 使用

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sinat_26279177/article/details/70807173 1       简介 ...