EF LIKE 查询

    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="CallCentersModel" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
       

 <Function Name="String_Like" ReturnType="Edm.Boolean">
          <Parameter Name="searchingIn" Type="Edm.String" />
          <Parameter Name="lookingFor" Type="Edm.String" />
          <DefiningExpression>
            searchingIn LIKE lookingFor
          </DefiningExpression>
        </Function>

  在edmx  文件中添加  Function 节点

    public static class EdmxExtensions
    {
        [EdmFunction("CallCentersModel", "String_Like")]
        public static Boolean Like(this String searchingIn, String lookingFor)
        {
            throw new Exception("Not implemented");
        }
    }

  

/*
string codeLike = id + "%";
var model = db.GetListByWhere(s => s.Code.Like(codeLike), s => new { s.Code, s.ProductID }, false).FirstOrDefault();
*/

  

原文地址:https://www.cnblogs.com/valeb/p/7444720.html