2
public static IQueryable<SearchProfile> FilterData(string Filter, Repository<SearchProfileContext> dc)
    {
        IQueryable<SearchProfile> data = null;
        var predicate = PredicateBuilder.True<SearchProfile>();
        Filter = ExcludedParam(Filter);
        if (!string.IsNullOrEmpty(Filter))`enter code here`
        {
            var stringToSplit = Filter;`enter code here`
            List<string[]> arrays = new List<string[]>();
            var primeArray = stringToSplit.Split('|');
            for (int i = 0; i < primeArray.Length; i++)
            {
                string first = primeArray[i];
                if (first.Contains("chkOrientation") == true)
                {
                    string[] Array = first.Replace("chkOrientation=", "").Split(',');
                    predicate = predicate.And(a => Array.Contains(a.OrientaionID.ToString()));
                }
                if (first.Contains("chkProfession") == true)
                {
                    string[] Array = first.Replace("chkProfession=", "").Split(',');
                    **predicate = predicate.And(a => Array.Contains(SqlFunctions.StringConvert((Double)a.ProfessionID)));**
                }
            }
            data = dc.Select<SearchProfile>().Where(predicate).Distinct();
            return data;
        }
        data = (from a in dc.Select<SearchProfile>().Where(a => a.PersonID > 0) select a).Distinct();
        return data;
    }

When I ran my program, I got this nasty error below:

LINQ to Entities does not recognize the method Int32 ToInteger(System.Object) method, and this method cannot be translated into a store expression.

then,I used SqlFunctions.StringConvert to make it work but the SQL LINQ generated was not evaluating. This is the sample output (it is comparing '1' and '2' instead of 1 and 2)**

Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44
user805661
  • 51
  • 1
  • 3

1 Answers1

0

Why are you casting a.ProfessionID to double? What type is a.ProfessionID of? I think there is implicit conversion to integer, which causes calling the ToInteger method.

And why don't you convert items in Array to integer in the first place, and then use Array of ints in the query?

Pz.
  • 1,119
  • 10
  • 14