Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么String.HtmlEncode无法识别?_Asp.net_Linq - Fatal编程技术网

Asp.net 为什么String.HtmlEncode无法识别?

Asp.net 为什么String.HtmlEncode无法识别?,asp.net,linq,Asp.net,Linq,我收到了下面的错误信息 LINQ to实体无法识别方法System.String HtmlEncode(System.String)method,此方法不能为空 翻译成商店表达式 使用这个LINQ语句 using (TranEntities model = new TranEntities()) { studentNames = (from source in model.Students where source.Name.Contain

我收到了下面的错误信息

LINQ to实体无法识别方法
System.String
HtmlEncode(System.String)
method,此方法不能为空 翻译成商店表达式

使用这个LINQ语句

using (TranEntities model = new TranEntities())
{
      studentNames = (from source in model.Students
                      where source.Name.Contains(pre)
                      select  System.Web.HttpUtility.HtmlEncode(source.Name.Replace(pre, "<span style='color : red'>" + pre + "</span>"))).ToList();
}
使用(TranEntities模型=新的TranEntities())
{
studentNames=(来自model.Students中的源)
其中source.Name.Contains(pre)
选择System.Web.HttpUtility.HtmlEncode(source.Name.Replace(pre,“+pre+”)).ToList();
}

您需要使用如下方法从LINQ到实体再到LINQ到对象进行一步:

using (TranEntities model = new TranEntities())
{
  var studentNamesE = (from source in model.Students
                  where source.Name.Contains(pre)
                  select source).AsEnumerable();

  studentNames = (from source in studentNamesE
                  select System.Web.HttpUtility
                             .HtmlEncode(source.Name.Replace(pre, 
                                         "<span style='color : red'>" + pre + "</span>")))
                 .ToList();
}
使用(TranEntities模型=新的TranEntities())
{
var studentNamesE=(来自model.Students中的源)
其中source.Name.Contains(pre)
选择源);
studentNames=(来自studentNamesE中的源)
选择System.Web.HttpUtility
.HtmlEncode(source.Name.Replace(pre,
“+pre+”))
.ToList();
}

您的问题是什么?很明显,这个问题涉及对错误消息的解释和解决方案。