LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method

后端 未结 4 1800
小蘑菇
小蘑菇 2021-02-19 22:30

I have executed a linq query by using Entityframework like below

GroupMaster getGroup = null;
getGroup = DataContext.Groups.FirstOrDefault(item => keyword.Ind         


        
4条回答
  •  时光取名叫无心
    2021-02-19 23:11

    The IndexOf method Of string class will not recognized by Entity Framework, Please replace this function with SQLfunction or Canonical functions

    You can also take help from here or maybe here

    You can use below code sample:

    DataContext.Groups.FirstOrDefault(item => 
        System.Data.Objects.SqlClient.SqlFunctions.CharIndex(item.Keywords, keyword).Value >=0 && item.IsEnabled)
    

提交回复
热议问题