-->
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.  [ 2 posts ] 
Author Message
 Post subject: Delete using Date Filter
PostPosted: Wed Oct 17, 2007 11:12 pm 
Newbie

Joined: Tue Sep 11, 2007 9:12 am
Posts: 4
i have try n try n try n again...

iam using mysql db n c# 2.0 n Nhibernate 1.2GA

i have table/entity "tblPriode" that have field "Begin" and the type is "Date"
now i want to delete the table tblPriode where Begin < DateTime.Today

i was try query like this with no syntax error but no row in tblPriode is deleted :
-----------------------------------------------
DateTime lessToDelete = new DateTime(2007,10,18);

ISession session = GetSession();
session.Delete("FROM tblPriode p WHERE (p.Begin < "+lessToDelete.ToShortDateString()+")");
session.Flush();

or

ISession session = GetSession();
session.Delete(string.Format("FROM tblPriode p WHERE (p.Begin < {0:yyyy/MM/dd})",lessToDelete)); /// or switch to {0:dd/MM/yyyy} or add the quota '{0:dd/MM/yyyy}'
session.Flush();

please help,,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 9:56 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
For a start, don't embed the date in your HQL but use a parameter instead.

session.Delete("FROM tblPriode p WHERE (p.Begin < ?)", lessToDelete, NHibernateUtil.DateTime);

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.