c# - Return list of string -
i need modify method mentioned below return list of strings . take contactid input , should return list of questionnaires
public string getfatcaquestionnaire(int contactid, string questionnairetype) { using (var context = new dbdealingcontainer()) { if (context.connection.state == connectionstate.closed) context.connection.open(); var fatcaquestionaires = context.fatcaquestionaires.firstordefault(p => p.contactid == contactid && p.questionnairetype == questionnairetype); return fatcaquestionaires != null ? fatcaquestionaires.questionaire : null; } }
new proposed method
public list<string> getfatcaquestionnaire(int contactid) { using (var context = new dbdealingcontainer()) { if (context.connection.state == connectionstate.closed) context.connection.open(); var fatcaquestionaires = context.fatcaquestionaires.select(p => p.contactid == contactid).tolist(); return fatcaquestionaires.tolist(); //return fatcaquestionaires.tolist() != null ? fatcaquestionaires : null; } }
actually need return list of fatcaquestonaires
. questionaire
, not whole fatcaquestonaires
object. 1 tell me how go it.
project out property want .select(x => x.myprop);
return fatcaquestionaires.select(x => x.questionaire).tolist();
Comments
Post a Comment