Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
C# Linq到Sql,其中条件字符串不受支持异常_C#_Linq_Linq To Sql - Fatal编程技术网

C# Linq到Sql,其中条件字符串不受支持异常

C# Linq到Sql,其中条件字符串不受支持异常,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我试图使用以下linq to sql查询从ASP.net表中提取密码长度 (from t1 in Aspnet_Users join t2 in Aspnet_Memberships on t1.UserId equals t2.UserId where decrypt(t2.Password).Length< 8 || decrypt(t2.Password).Length>16 select new { t1.UserName, t2.Email, Length=

我试图使用以下linq to sql查询从ASP.net表中提取密码长度

(from t1 in Aspnet_Users join t2 in Aspnet_Memberships
on t1.UserId equals t2.UserId
where decrypt(t2.Password).Length< 8 ||
  decrypt(t2.Password).Length>16
  select new { t1.UserName,
  t2.Email,
  Length=decrypt(t2.Password).Length})
(从Aspnet\u中的t1开始,用户加入Aspnet\u成员中的t2
在t1.UserId上等于t2.UserId
其中解密(t2.密码)。长度<8||
解密(t2.密码)。长度>16
选择新的{t1.UserName,
t2.电子邮件,
长度=解密(t2.Password).Length})
但是当我尝试运行此代码时。我得到以下错误

NotSupportedException:方法“System.String a(System.String)”没有支持的SQL转换

你们能给我一些想法来修复它吗?

你们不能在Linq to SQL中使用C方法,在这种情况下是
解密
。这适用于LINQtoObject,但不适用于LINQtoSQL,因为整个Linq查询被转换为SQL查询,然后编译器无法识别您的方法


为此,您可以将此linq代码转换为lambda表达式,并为您的解密创建一个
Func
委托,并在where子句中使用它。

解决此问题的方法是将(linq转换为Sql).ToList()转换并在其上应用where。虽然花了一些时间,但还是奏效了。