Linq-内部联接未从左表中检索所有记录

本文关键字:检索 记录 内部 Linq- | 更新日期: 2023-09-27 18:25:44

我已经完成了一个内部联接,它只显示匹配的记录和以下查询:-

var data = from t1 in ctx.tblEmp
           join t2 in ctx.tblHelp 
               on t1.Field equals t2.Fld
           where t1.Id == Id && 
                 t2.Id == Id
           select new Settings { Master = t1.Labelname, OrderNo = t2.OrderNo};

我想要tblEmp&仅匹配来自CCD_ 2的记录。

如何做到这一点?

Linq-内部联接未从左表中检索所有记录

用作

 var data = from t1 in ctx.tblEmp
       join t2 in ctx.tblHelp 
           on t1.Field equals t2.Fld into u
           from t2 in u.DefaultIfEmpty()
       where t1.Id == Id && 
             t2.Id == Id
       select new Settings { Master = t1.Labelname, OrderNo = t2.OrderNo};

试试这个

 var data = from t1 in ctx.tblEmp
       join t2 in ctx.tblHelp 
           on t1.Field equals t2.Fld into u
           from t2 in u.DefaultIfEmpty()
       where t1.Id == Id 
       orderby columnname // Added Order By
       select new Settings { Master = t1.Labelname, OrderNo = t2.OrderNo==null ?"":t2.OrderNo};
    var query = from t1 in ctx.tblEmp
                    join t2 in ctx.tblHelp on t1 equals t2.Fld into tempGroup
                    from subpet in tempGroup.DefaultIfEmpty()
                    select new { t1.Labelname, OrderNo = (subpet == null ? String.Empty : subpet.OrderNo) };