LINQ to Entities does not recognize the method

前端 未结 3 1779
遇见更好的自我
遇见更好的自我 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:34

    I got the same error in this code:

     var articulos_en_almacen = xx.IV00102.Where(iv => alm_x_suc.Exists(axs => axs.almacen == iv.LOCNCODE.Trim())).Select(iv => iv.ITEMNMBR.Trim()).ToList();
    

    this was the exactly error:

    System.NotSupportedException: 'LINQ to Entities does not recognize the method 'Boolean Exists(System.Predicate`1[conector_gp.Models.almacenes_por_sucursal])' method, and this method cannot be translated into a store expression.'

    I solved this way:

    var articulos_en_almacen = xx.IV00102.ToList().Where(iv => alm_x_suc.Exists(axs => axs.almacen == iv.LOCNCODE.Trim())).Select(iv => iv.ITEMNMBR.Trim()).ToList();
    

    I added a .ToList() before my table, this decouple the Entity and linq code, and avoid my next linq expression be translated

    NOTE: this solution isn't optimal, because avoid entity filtering, and simply loads all table into memory

提交回复
热议问题