NHibernate.Linq LIKE

前端 未结 4 1315
眼角桃花
眼角桃花 2021-02-12 10:02

How can I produce this query using NHibernate.Linq?

WHERE this_.Name LIKE @p0; @p0 = \'test\'  // Notice NO % wild card

Note, this is not Linq

4条回答
  •  攒了一身酷
    2021-02-12 10:28

    I had the same problem in my project and found a solution :

    session.Linq()
        .Where(x => x.Name.StartsWith("test") && x.Name.EndsWith("test");
    

    This translates in SQL to

    SELECT ... WHERE Name LIKE '%test' AND Name LIKE 'test%'
    

提交回复
热议问题