NHibernate include/exclude all
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>();
精彩评论