Don't think so, unfortunately - my reading of that is that it'll produce
a table with two columns (Name and pricerange) with a row per Product?
My requirement is to produce a scalar result (0 or 1) depending upon
whether there is / is not an entity meeting the condition - effectively
I want a QueryOver<void>.

 

As an aside, I believe that the 'case' part is actually
Projections.Conditional, so "case when price < 100 then 1 else 2 end as
pricerange" could be refactored slightly as
Projections.Conditional(Restrictions.Lt(x => x.Price, 100),
Projections.Constant(1), Projections.Constant(2))

 

Thanks for the suggestion :)

 

/Pete

 

From: [email protected] [mailto:[email protected]] On
Behalf Of Ricardo Peres
Sent: 02 May 2013 10:40
To: [email protected]
Subject: [nhusers] Re: Determine the existence of an entity meeting a
condition

 

You know you can mix Query Over with Criteria, so you can use something
like:

 

var l =
session.QueryOver<Product>().Select(NHibernate.Criterion.Projections.Pro
perty<Product>(x => x.Name),
NHibernate.Criterion.Projections.SqlProjection("case when price < 100
then 1 else 2 end as pricerange", new String[] { "pricerange" }, new
IType[] { NHibernateUtil.String })).List<Object[]>();

 

Will that do?

 

RP

On Thursday, May 2, 2013 10:16:52 AM UTC+1, PeteA wrote:

I know this should be simple, but I seem to be being brain-dead today...
given some entity Foo, how can I write a QueryOver that translates into
the following SQL:

 

select case

                when exists (select 1 from FooTable where Name='some
name') then 1

                else 0

end

 

I.E. - I want to be able to determine in code if the entity already
exists; counting them would be trivial, but I don't want to do that
because there could be a lot and it's a significant amount of
unnecessary work for the DB.  The inner subquery is easy enough - how do
I generate the outer query though, which doesn't have a 'from'
statement?

 

Thanks,

 

/Pete

-- 
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to