选择子句null

时间:2013-06-07 12:45:04

标签: c# .net linq

我目前正在使用

your = from p in (toSelect)
select new
{
  last = p.Last,
  current = p.CurrentPlayer,
  seats = from s in (p.Seated)
  select new
  {
      UID = s.UID,
      buyin = s.BuyIn
  }
}

p.Seated是一个数组,每次null未设置时如何通过s.UID?我知道“where”,但我知道哪些座位是免费的(例如null

希望这很清楚。

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

your = from p in (toSelect)
select new
{
  last = p.Last,
  current = p.CurrentPlayer,
  seats = p.Seated.Select(s => s.UID != null
    ? new
      {
          UID = s.UID,
          buyin = s.BuyIn
      }
    : null;
}

答案 1 :(得分:0)

将您分配给seats的表达式替换为:

seats = p.Seated.Select(s => s != null ? new { UID = s.UID, buyin = s.BuyIn } : null)
  

希望这很清楚。

我说实话。它不够清楚。 s.UID是否为可空类型,我们需要与null进行比较?