如何在Linq-2-Entity中结合不同的类型

时间:2018-05-24 14:31:58

标签: linq linq-to-sql linq-to-entities union

我正试图像网格一样得到结果!上面有标题和值。试图这样做。

void Main()
{
    var ctx = dbContext;
    (from tQuestions in ctx.Questions
        select new 
        {
            a1_1 = (Object)tQuestions.HeaderCreationDate //varchar(max)(sometning like "Creation Date")
        }
    ).Union<Object>(from tAnswers in ctx.Answers
        select new{
        a1_1 = (Object)tAnswers.CreationDate //DateTime (something like "2018-05-24 00:00:00.000")
        }
    ).Dump();
}

结果如下:“从字符串转换日期和/或时间时转换失败。”

1 个答案:

答案 0 :(得分:0)

解决!

void Main()
{
    var ctx = dbContext;
   (from tQuestion in ctx.Questions
        select new 
        {
            cod = (object)tQuestion.Id ,
            r1_1 = (object)tQuestion.R1_1 //varchar(max)(sometning like "Creation Date")
        }
    ).ToList().Concat(from tAnswer in ctx.Answers
        select new{
                      cod = (object)tAnswer.Id,
                      r1_1 = (object)tAnswer.CreationDate //DateTime (something like "2018-05-24 00:00:00.000")
                  }
   ).ToList().Dump();
}

谢谢社区!!