LINQ to Entities 无法识别方法 'System.String Decrypt(System.String, System.String)' 方法
LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method
我正在尝试通过使用电子邮件进行过滤来在 combobox
中显示电子邮件。我的问题是我的数据在用户 table.
中被加密
当我尝试解密它时出现此错误:
LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method, and this method cannot be translated into a store expression
如何解决这个错误?
这是我的查询class
public class Lookup
{
public long boundvalue { get; set; }
public string boundtext { get; set; }
}
这是我要过滤的代码
public IEnumerable<Lookup> getUser(string fText)
{
var ret = new List<Lookup>
{
new Lookup
{
boundvalue = 0,
boundtext = ""
}
};
if (!string.IsNullOrEmpty(fText))
{
ret.AddRange(_entities.Users.Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
}
return ret;
}
请记住,最后的 Linq to Entities 查询已转换为 sql 表示法,但错误的意思是 System.String Decrypt
目前不支持进行该转换。这就是为什么我担心你不能在服务器端应用过滤器,你需要在内存中进行。为此,请使用 AsEnumerable
扩展方法切换到 Linq to Objects
ret.AddRange(_entities.Users.AsEnumerable().Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
我已经设法找到了解决方案,这只是一个小问题。
我应该包括 ToList()
ret.AddRange(_entities.Users.ToList().Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
现在可以使用了。
我正在尝试通过使用电子邮件进行过滤来在 combobox
中显示电子邮件。我的问题是我的数据在用户 table.
当我尝试解密它时出现此错误:
LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method, and this method cannot be translated into a store expression
如何解决这个错误?
这是我的查询class
public class Lookup
{
public long boundvalue { get; set; }
public string boundtext { get; set; }
}
这是我要过滤的代码
public IEnumerable<Lookup> getUser(string fText)
{
var ret = new List<Lookup>
{
new Lookup
{
boundvalue = 0,
boundtext = ""
}
};
if (!string.IsNullOrEmpty(fText))
{
ret.AddRange(_entities.Users.Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
}
return ret;
}
请记住,最后的 Linq to Entities 查询已转换为 sql 表示法,但错误的意思是 System.String Decrypt
目前不支持进行该转换。这就是为什么我担心你不能在服务器端应用过滤器,你需要在内存中进行。为此,请使用 AsEnumerable
扩展方法切换到 Linq to Objects
ret.AddRange(_entities.Users.AsEnumerable().Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
我已经设法找到了解决方案,这只是一个小问题。
我应该包括 ToList()
ret.AddRange(_entities.Users.ToList().Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
.Select(select => new Lookup
{
boundvalue = select.UserID,
boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
}));
现在可以使用了。