Reputation: 1351
My udf:
[EdmFunction("Model.Store", "Decrypt")]
public static string Decrypt(byte[] Value, string Passphrase)
{
throw new NotSupportedException("Direct calls are not supported.");
}
My LINQ call:
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.
SQL function
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:
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.
Which still leads me to believe something is wrong with the varbinary equvialent in C#
Upvotes: 2
Views: 775
Reputation: 1351
The answer was so simple. My EdmFunction was using the wrong reference due to resharper's advice.... the correct class to be using is
using System.Data.Entity.Core.Objects.DataClasses;
Sorry for bringing the headache to you all, thanks for all of your efforts!
Upvotes: 1
Reputation: 21480
Linq to Entities is trying to expand to something like;
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. 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;
Upvotes: 1