嗨当我使用查询转换API时,是否有任何优雅的方式组合'喜欢'和'或'?对于'喜欢'有类似的东西:
query.WhereRestrictionOn(x=>x.Code).IsLike(codePart)
Run Code Online (Sandbox Code Playgroud)
对于'或'我可以做类似的事情:
query.Where( x=>x.Code == codePart || x.Description== codePart)
Run Code Online (Sandbox Code Playgroud)
但是如何创建这样的查询:
select*from n,其中代码如'%abc%'或描述如'%abc%'
我使用子查询获得以下NHibernate查询:
NHContext.Session.QueryOver<Item>()
.WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Foo>().Where(x => x.AFlag).Select(x => x.ItemId))
.WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Bar>().Where(x => x.AFlag).Select(x => x.Item))
.Future<Item>();
Run Code Online (Sandbox Code Playgroud)
这将运行以下SQL:
SELECT *
FROM item this_
WHERE this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Foo this_0_
WHERE this_0_.AFlag = 1 /* @p0 */)
and this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Bar this_0_
WHERE this_0_.AFlag = 1 /* @p0 */)
Run Code Online (Sandbox Code Playgroud)
我希望它使用OR,例如:
SELECT *
FROM item this_
WHERE this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Foo this_0_
WHERE this_0_.AFlag = 1 /* …Run Code Online (Sandbox Code Playgroud)