Using DefaultIfEmpty in Linq - problem substituting a null value for a default value
Posted
by FiveTools
on Stack Overflow
See other posts from Stack Overflow
or by FiveTools
Published on 2010-05-21T17:56:50Z
Indexed on
2010/05/21
18:00 UTC
Read the original article
Hit count: 270
I have questions that may or may not have a question_group
if all the questions do not have a question_group and if I use default if empty like this:
question_group defaultQuestion = new question_group {question_group_id = Guid.Empty};
questions.Select(x => x.question_group).DefaultIfEmpty(defaultQuestion).Distinct();
shouldn't I get an IEnumerable<question_group>
containing only the default question_group that I defined? I get null.... what am I missing here?
© Stack Overflow or respective owner