LINQ查询结果连接在一起

时间:2010-01-12 23:39:32

标签: linq-to-sql

想知道我是否可以有条件地连接表中4个不同字段的LINQ查询结果,这些字段是每个记录的1个字符串,所以它会是这样的:

            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; }


    }

有没有办法以那种方式做到这一点?感谢

1 个答案:

答案 0 :(得分:1)

我不确定我是否理解您的问题,但我只想在ContactLog课程中添加新属性,如下所示:

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);
      }
   }
}

无需使用

加载linq查询