LINQ query result concatenated
Wondering if I can conditionally concatenate LINQ query results from 4 different fields in a table, which are flags into 1 st开发者_高级运维ring for each record, so it would be something like this:
dbContext.CONTACT_LOGs.Select( e => new
(e => new ContactLog
{
rec1 = e.Recommend1 ? "1 is recommended" : String.Empty,
rec2 = e.Recommend2 ? "2 is recommended" : String.Empty,
rec3 = e.Recommend3? "3 is recommended" : String.Empty,
rec4 = e.Recommend4 ? "4 is recommended" : String.Empty
//this doesn't work in a single query
ContactSummary = String.Concat(rec1, rec2, rec3, rec4)
});
public class ContactLog
{
public string rec1 { get; set; }
public string rec2 { get; set; }
public string rec3 { get; set; }
public string rec4 { get; set; }
public string ContactSummary { get; set; }
}
Is there any way to do that in that fashion? Thanks
I'm not sure if I understand your question, but I would just add a new property to your ContactLog
class as follows:
public class ContactLog {
public string rec1 { get; set; }
public string rec2 { get; set; }
public string rec3 { get; set; }
public string rec4 { get; set; }
public string ContactComments { get; set; }
public string ContactLog {
get {
return String.Concat(rec1, rec2, rec3, rec4);
}
}
}
No need to burden the linq query with that
精彩评论