LINQ内部查询返回null

时间:2019-01-29 11:25:52

标签: c# list linq

我有2个简单的列表:

当我尝试这样的简单查询时,我的代码返回null:

var linq = from s in mojUser
           from us in mojDev
           // join us in mojUser on s.DeviceId equals us.UserId
           where s.UserId==us.DeviceId
           select new
           {
             user = s.UserMac
           }

2 个答案:

答案 0 :(得分:1)

尝试

var linq = from s in mojUser
           join us in mojDev on s.UserId equals us.DeviceId
           select new
           {
             user = s.UserMac
           }

答案 1 :(得分:0)

您缺少join语句;

var linq = from s in mojUser
           join us in mojDev on s.UserId==us.DeviceId
           select new
           {
             s.UserMac
           }

或使用扩展方法:

   var linq = mojUser.Join(mojDev,
          s => s.UserId,
          us => us.DeviceId,
          (s, us) => new { s.UserMac });