Using DefaultIfEmpty in Linq - problem substituting a null value for a default value
- by FiveTools
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?