-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: nHibernate criteria for continuity check
PostPosted: Sat Feb 27, 2010 3:55 pm 
Newbie

Joined: Sat Feb 27, 2010 3:50 pm
Posts: 2
I need to do continuity check on data in table .
In SQL it could be done by simple join query like this:

select l.id + 1 as start
from ContSeq as l
WHERE NOT EXISTS(SELECT 1 from ContSeq as r WHERE l.id + 1 = r.id)

Can you help me to convert it to NHibernate criteria in C#?


Top
 Profile  
 
 Post subject: Re: nHibernate criteria for continuity check
PostPosted: Sat Feb 27, 2010 9:35 pm 
Newbie

Joined: Sat Feb 27, 2010 9:26 pm
Posts: 5
I think you can use "Linq 2 Nhibernate" to solve your problem


Top
 Profile  
 
 Post subject: Re: nHibernate criteria for continuity check
PostPosted: Sun Feb 28, 2010 4:41 am 
Newbie

Joined: Sat Feb 27, 2010 3:50 pm
Posts: 2
Linq 2 NHibernate is for SQL Server database only.
Also it could be solved by HQL query but HQL is kind of script and this technic has problems like using dynamic SQL.

So i think the best solution is using crieteria object.
I made some progress this is my nhibernate criteria code

Code:
var criteria = session.CreateCriteria(typeof(Continuity),"r");
var subCriteria = DetachedCriteria.For<Continuity>("l");

subCriteria.SetProjection(Projections.Constant(1));
subCriteria.Add(Restrictions.EqProperty("r.Id", "l.Id"));

criteria.Add(Subqueries.NotExists(subCriteria));


This code creates the this SQL Query:

select l.id as start
from ContSeq as l
WHERE NOT EXISTS(SELECT 1 from ContSeq as r WHERE l.id = r.id)


I need help to complate the criteria to produce this query

select l.id + 1 as start
from ContSeq as l
WHERE NOT EXISTS(SELECT 1 from ContSeq as r WHERE l.id + 1 = r.id)


Top
 Profile  
 
 Post subject: Re: nHibernate criteria for continuity check
PostPosted: Sun Feb 28, 2010 10:24 am 
Newbie

Joined: Sat Feb 27, 2010 9:26 pm
Posts: 5
alexch13@gmail.com wrote:
Linq 2 NHibernate is for SQL Server database only.
??? I use "Linq to nHibernate" with PostgreSQL and it works fine. It's not limited to SQL-Server.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.