LINQ to Entities does not recognize the method

前端 未结 3 1778
遇见更好的自我
遇见更好的自我 2020-11-22 00:40

I\'m getting the following error when trying to do a linq query:

LINQ to Entities does not recognize the method \'Boolean IsCharityMatching(System.S

3条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 01:31

    As you've figured out, Entity Framework can't actually run your C# code as part of its query. It has to be able to convert the query to an actual SQL statement. In order for that to work, you will have to restructure your query expression into an expression that Entity Framework can handle.

    public System.Linq.Expressions.Expression> IsSatisfied()
    {
        string name = this.charityName;
        string referenceNumber = this.referenceNumber;
        return p => 
            (string.IsNullOrEmpty(name) || 
                p.registeredName.ToLower().Contains(name.ToLower()) ||
                p.alias.ToLower().Contains(name.ToLower()) ||
                p.charityId.ToLower().Contains(name.ToLower())) &&
            (string.IsNullOrEmpty(referenceNumber) ||
                p.charityReference.ToLower().Contains(referenceNumber.ToLower()));
    }
    

提交回复
热议问题