火焰

valeb
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

EF LIKE 查询

Posted on 2017-08-28 17:14  valeb  阅读(579)  评论(0编辑  收藏  举报
    <!-- 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();
*/