[英]Unexpected Error : LINQ to Entities does not recognize the method 'System.String DecryptValue(Byte[], System.String)' method
My udf:我的 udf:
[EdmFunction("Model.Store", "Decrypt")]
public static string Decrypt(byte[] Value, string Passphrase)
{
throw new NotSupportedException("Direct calls are not supported.");
}
My LINQ call:我的 LINQ 电话:
var passphrase = "phrase123";
var decryptedValue = (from p in unitOfWork.context.Values
where p.ValueID== valueId
select Decrypt(p.value, passphrase)).FirstOrDefault();
This is the actual error message:这是实际的错误消息:
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.
意外错误:LINQ to Entities 无法识别“System.String Decrypt(Byte[], System.String)”方法,并且此方法无法转换为存储表达式。
SQL function SQL函数
CREATE FUNCTION DB.Decrypt
(
@Value VARBINARY(200),
@Passphrase varchar(1000)
)
RETURNS VARCHAR(1000)
How do i fix this in order to decrypt the value?我如何解决这个问题以解密该值? Thanks
谢谢
UPDATE : I changed my edmfunction to try to handle the varbinary to this:更新:我更改了我的 edmfunction 以尝试将 varbinary 处理为:
public static string Decrypt(SqlBinary Value, string Passphrase)
And got a new error message of this:并收到了一条新的错误消息:
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.
LINQ to Entities 无法识别方法 'System.String Decrypt(System.Data.SqlTypes.SqlBinary, System.String)' 方法,并且此方法无法转换为存储表达式。
Which still leads me to believe something is wrong with the varbinary equvialent in C#这仍然让我相信 C# 中的 varbinary equivalent 有问题
Linq to Entities is trying to expand to something like; Linq to Entities 正试图扩展到类似的东西;
select Decrypt(p.Value, @passphrase)
from values p
where p.valueid = @valueId
and it seems to be having trouble matching your code's Decrypt function with the matching one on the server.并且似乎无法将您的代码的 Decrypt 函数与服务器上的匹配函数相匹配。 It looks ok, from other examples I've seen, so I suspect it's a minor 'glue' issue...
从我见过的其他例子来看,它看起来没问题,所以我怀疑这是一个小“胶水”问题......
I wonder if any of these might be useful leads;我想知道这些是否可能是有用的线索;
The answer was so simple.答案就这么简单。 My EdmFunction was using the wrong reference due to resharper's advice.... the correct class to be using is
由于 resharper 的建议,我的 EdmFunction 使用了错误的参考......要使用的正确类是
using System.Data.Entity.Core.Objects.DataClasses;
Sorry for bringing the headache to you all, thanks for all of your efforts!抱歉给大家带来了头疼,感谢大家的努力!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.