我的udf:
[EdmFunction("Model.Store", "Decrypt")]
public static string Decrypt(byte[] Value, string Passphrase)
{
throw new NotSupportedException("Direct calls are not supported.");
}
我的 LINQ 调用:
var passphrase = "phrase123";
var decryptedValue = (from p in unitOfWork.context.Values
where p.ValueID== valueId
select Decrypt(p.value, passphrase)).FirstOrDefault();
这是实际的错误消息:
Unexpected Error : LINQ to Entities does not recognize the method 'System.String Decrypt(Byte[], System.String)' method, and this method cannot be translated into a store expression.
SQL函数
CREATE FUNCTION DB.Decrypt
(
@Value VARBINARY(200),
@Passphrase varchar(1000)
)
RETURNS VARCHAR(1000)
我该如何解决这个问题才能解密该值?谢谢
更新: 我更改了 edmfunction 以尝试将 varbinary 处理为:
public static string Decrypt(SqlBinary Value, string Passphrase)
并收到一条新的错误消息:
LINQ to Entities does not recognize the method 'System.String Decrypt(System.Data.SqlTypes.SqlBinary, System.String)' method, and this method cannot be translated into a store expression.
这仍然让我相信 C# 中的 varbinary 等价物有问题
最佳答案
Linq to Entities 正在尝试扩展到类似的内容;
select Decrypt(p.Value, @passphrase)
from values p
where p.valueid = @valueId
并且似乎无法将代码的 Decrypt 函数与服务器上的匹配函数进行匹配。从我见过的其他例子来看,它看起来不错,所以我怀疑这是一个小“粘合”问题......
我想知道这些是否可能是有用的线索;
- C# Decrypt() 将 byte[] 作为第一个参数——这是 p.value 的实际数据类型吗?例如,如果它是一个字符串,您可能需要微调函数声明中的类型。
- 您确实在当前连接的数据库上获得了该功能吗?也许缺少某种更新?
关于c# - 意外错误 : LINQ to Entities does not recognize the method 'System.String DecryptValue(Byte[], System.String)' method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37168703/