locked
LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method, and this method cannot be translated into a store expression RRS feed

  • Question

  • Hi good people (developers / programmers).

    Ladies and Gents I have a problem here. I am trying to display email in combobox by filtering using email. My problem is that my data is Encrypted in the users table.

    When I am trying to Decrypt it it giving this error

    LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method, and this method cannot be translated into a store expression


    How can I solve this error any one have a good idea please?

    Here is my Lookup class

        public class Lookup
        {
            public long boundvalue { get; set; }
            public string boundtext { get; set; }
        }

    Here is my code to filter

    public IEnumerable<Lookup> getUser(string fText)
                {
                    var ret = new List<Lookup>
                                  {
                                      new Lookup
                                          {
                                              boundvalue = 0,
                                              boundtext = ""
                                          }
                                  };
                    if (!string.IsNullOrEmpty(fText))
                    {
                        ret.AddRange(_entities.Users.Where(x =>EncDec.Decrypt(x.UserVar01.Trim().Replace("_",string.Empty), 
                        Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)).Contains(fText.Trim()))
                                     .Select(select => new Lookup
                                     {
                                         boundvalue = select.UserID,
                                         boundtext = EncDec.Decrypt(select.UserVar01.Trim().Replace("_", string.Empty),
                                         Enums.EncDecSecKeyToString(Enums.EncDecSecKey.Email)),
                                     }));
    
                    }
                    return ret;
                }

    Please help me guys

    • Moved by CoolDadTx Friday, September 23, 2016 2:57 PM EF related
    Wednesday, September 21, 2016 5:33 PM

Answers

All replies

  • Check this temporary workaround, which uses ToList:

        … _entities.Users.ToList().Where(…

    Wednesday, September 21, 2016 6:15 PM
  • Maybe, the workaround will work for you, but the error message that the Linq statement you created cannot be translated into a T-SQL query by the Linq engine that can be submitted to the DB engine for execution.
    Wednesday, September 21, 2016 6:21 PM
  • Hi Mzwe,

    As DA924x said. Entity framework can not translate c# method into a T-SQL query. we could convert IQueryable  result into the in-memory collection as Viorel_ mentioned by using ToList method or AsEnumerable() method. then we could use c# method.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 26, 2016 5:41 AM