“Only arguments that can be evaluated on the client are supported for the String.Contains method”

后端 未结 2 1866
刺人心
刺人心 2021-01-18 04:56
public static void MyFunction(MyErrorClass err)
{
    var query = from filter in DataContext.ErrorFilters select filter;
    query = query.Where(f => err.ErrorMes         


        
2条回答
  •  情书的邮戳
    2021-01-18 05:44

    Hmm... It seems the Linq2SQL IndexOf translation is smarter than for Contains. This should work:

    public static void MyFunction(MyErrorClass err)
    {
        var query = DataContext.ErrorFilters;
        query = query.Where(f => err.ErrorMessage.IndexOf(f.ErrorMessage)>=0);
        List filters = query.ToList();
        //...more code
    }
    

    In LinqPad it can be seen this uses CHARINDEX, because we've asked for more than just "contains", rather "where is it", but it is happy to work with server-side expressions.

提交回复
热议问题