相关疑难解决方法(0)

查询和(x像'a'或y喜欢'a')

嗨当我使用查询转换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 queryover

50
推荐指数
3
解决办法
2万
查看次数

QueryOver或子查询

我使用子查询获得以下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)

nhibernate queryover

23
推荐指数
1
解决办法
1万
查看次数

标签 统计

nhibernate ×2

queryover ×2