简体   繁体   English

意外错误:LINQ to Entities 无法识别方法“System.String DecryptValue(Byte[], System.String)”方法

[英]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;我想知道这些是否可能是有用的线索;

  • C# Decrypt() takes a byte[] as the first parameter -- is that the actual datatype of p.value? C# Decrypt() 将 byte[] 作为第一个参数——这是 p.value 的实际数据类型吗? If it's a string, for instance, you might need to nudge the types in the function declaration.例如,如果它是一个字符串,您可能需要微调函数声明中的类型。
  • Have you definitely got the function on the database you're currently connecting to?您确定在当前连接的数据库上获得了该功能吗? Maybe missing some kind of update?也许错过了某种更新?

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.

相关问题 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 LINQ to Entities无法识别方法'System.String getFullname(System.String,System.String)' - LINQ to Entities does not recognize the method 'System.String getFullname(System.String, System.String)' LINQ to Entities无法识别方法'System.String [] ToArray [String] - LINQ to Entities does not recognize the method 'System.String[] ToArray[String] LINQ to Entities无法识别方法'System.String ToString()'方法++++++ - LINQ to Entities does not recognize the method 'System.String ToString()' method ++++++ LINQ to Entities无法识别方法'System.String - LINQ to Entities does not recognize the method 'System.String LINQ to Entities无法识别方法'System.String Format - LINQ to Entities does not recognize the method 'System.String Format LINQ to Entities无法识别方法'System.String IfNullOrWhiteSpace' - LINQ to Entities does not recognize the method 'System.String IfNullOrWhiteSpace' LINQ to Entities无法识别方法ToDateTime(System.String) - LINQ to Entities does not recognize the method ToDateTime(System.String) LINQ to Entities无法识别方法'System.String get_Item(System.String)', - LINQ to Entities does not recognize the method 'System.String get_Item (System.String)', LINQ to Entities无法识别方法'System.String LetterType(Byte)',并且该方法无法转换为商店表达式 - LINQ to Entities does not recognize the method 'System.String LetterType(Byte)' method, and this method cannot be translated into a store expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM