C# 实体框架文本数据分组依据

C# 实体框架文本数据分组依据,c#,sql,sql-server,asp.net-mvc,entity-framework-6,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))

我运行这个查询

    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();
var myList=(从p到db.Full)
其中((p.date_Receivement>开始和p.date_Receivement<结束)&
p、 mc_host.Contains(主机)和p.mc_host_class.Contains(主机类))
p.msg将p分组为g
orderby g.Count()降序
选择新的StringIntType
{
str=g.键,
nbr=g.计数()
}).Take(20)ToList();
我得到这个错误:

文本、ntext和图像数据类型不能进行比较或排序,除非使用IS NULL或LIKE运算符

有办法解决这个问题吗


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

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

您是否试图找出出现此错误的原因?如果你只是用谷歌搜索一下,它上面有很多资源。是的,当我使用另一个varchar类型的列而不是msg@krilovich我刚刚通过将数据库中的数据类型从text转换为varchar解决了这个问题。谢谢你,@drexdrex的可能副本将其作为答案,然后接受,以便其他人可以使用它。另外,请在您的问题中指定您使用了
text
作为数据类型