开发者

NHibernate include/exclude all

开发者 https://www.devze.com 2022-12-10 19:44 出处:网络
I\'m building a complex security mechanism to filter access to objects depending on various rights. As part of this I want to have an initial OR in my query that excludes all poss开发者_如何转开发ibl

I'm building a complex security mechanism to filter access to objects depending on various rights.

As part of this I want to have an initial OR in my query that excludes all poss开发者_如何转开发ible results from the query before the permissions allow access to certain subsets. In SQL it would look like this:

select   *
from     Table
where    (1 = 0)
or       ( /* various predicates */ )

However, I'm not sure how to create that initial 1 = 0 through the criteria API. I will probably need to create 1 = 1 at some point too but I'm assuming that will be a similar task.

How do I do this?


Tuna Toksoz has suggested this method which is simple and clear:

var stuff = session.CreateCriteria<Stuff>()
    .Add(Restrictions.Eq(Projections.Constant(1), 0))
    .List<Stuff>();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号