Querying with NHibernate

后端 未结 3 1598
迷失自我
迷失自我 2021-02-04 17:08

I am new to NHibernate and I am trying to learn how to query my data.

Below is the configuration xml. Only the recipe is shown.

I want to be able to query recipe

3条回答
  •  逝去的感伤
    2021-02-04 17:38

    Both Stefan's and Sathish's examples concatenate % operators into the SQL. This is unnecesary as Restrictions.Like (nhib 2.0+) and Expression.Like (before v2.0) have 3 parameter versions with a MatchMode.

    Disjunction keywordsCriteria = Restrictions.Disjunction();
    foreach (var keyword in keywords)
    {
        keywordsCriteria.Add(Restrictions.Like("i.IngredientName", keyword, MatchMode.Anywhere));
        keywordsCriteria.Add(Restrictions.Like("r.RecipeTitle", keyword, MatchMode.Anywhere));
    }
    

    Full text queries are also available with NHibernate Search. See Ayende's example for more details.

提交回复
热议问题