user2462729
user2462729

Reputation: 53

Select clause null

I am currently using

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 is an array, how can I pass null every time s.UID is unset? I know about "where" but I was to know which seats are free (e.g. null)

Hope this is clear enough.

Upvotes: 2

Views: 87

Answers (2)

jason
jason

Reputation: 241631

Replace your expression that you're assigning to seats with:

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

Hope this is clear enough.

I'll be honest. It's not clear enough. Is s.UID a nullable type and that's what we need to compare to null?

Upvotes: 0

Serge
Serge

Reputation: 6692

You could try this:

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;
}

Upvotes: 2

Related Questions