实体框架TEXT数据组

时间:2015-03-04 14:47:20

标签: c# sql sql-server asp.net-mvc entity-framework-6

我运行此查询

    var myList = (from p in db.Full
                  where ((p.date_reception > begin & p.date_reception < end ) &
                          p.mc_host.Contains(host) & p.mc_host_class.Contains(hostClass))
                  group p by p.msg into g
                  orderby g.Count() descending
                  select new StringIntType
                         {
                              str = g.Key,
                              nbr = g.Count()
                         }).Take(20).ToList();

我收到此错误:

  

text,ntext和image数据类型无法进行比较或排序,除非使用IS NULL或LIKE运算符。

有没有办法解决这个问题?

注意: msg列的数据类型是数据库中的文本。

1 个答案:

答案 0 :(得分:0)

我刚刚通过将数据库中的数据类型从text更改为varchar来解决它 通过使用cast(msg as varchar(max))msg