score:0

Accepted answer

Project out the property you want with .Select(x => x.MyProp);

return fatcaQuestionaires.Select(x => x.Questionaire).ToList();

score:6

Using Linq, first you can do a Where filtering the desired rows, and then Select to projecting only Questionaire properties.

Try this

return context.FatcaQuestionaires
    .Where(p => p.ContactID == contactId)
    .Select(p => p.Questionaire)
    .ToList();

score:4

You almost have it. Select invokes a transformation function, so it is just making a list of bool. You need a Where clause to do the filtering, and then a Select.

var fatcaQuestionaires = context.FatcaQuestionaires
                        .Where(p => p.ContactID == contactId)
                        .Select(p => p.Quentionaire);

return fatcaQuestionaires.ToList();

score:1

Change Select to Where as I mentioned in my comment. Select will just return a bool value for every entry's evaluation base on your lambda expression. So you end up with a List<bool>

 var fatcaQuestionaires = context.FatcaQuestionaires
    .Where(p => p.ContactID == contactId)
    .Select(q=>q.Questionaire).ToList();
 return fatcaQuestionaires;

score:2

What you have written looks like it will return a list of booleans and not compile. What you need is a combination of a where clause and a select clause.

return context.FatcaQuestionaires
    .Where(p => p.ContactID == contactId)
    .Select(p => p.Questionaire).ToList();

Where() is what limits the FactaQuesntionaires, and Select() is where you choose the property to return. You can also write it like this:

return (from p in context.FatcaQuestionaires
        where p.ContactID == contactId
        select p.Questionaire).ToList();

Related Articles