NHibernate - define where condition
        Posted  
        
            by 
                t.kehl
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by t.kehl
        
        
        
        Published on 2011-01-09T12:44:01Z
        Indexed on 
            2011/01/09
            12:53 UTC
        
        
        Read the original article
        Hit count: 311
        
Hi.
In my application the user can defines search-conditions. He can choose a column, set an operator (equals, like, greater than, less or equal than, etc.) and give in the value. After the user clicks on a button and the application should do a search on the database with the condition. I use NHibernate and ask me now, what is the efficientest way to do this with NHibernate.
Should I create a query with it like (Column=Name, Operator=Like, Value=%John%)
        var a = session.CreateCriteria<Customer>();
        a.Add(Restrictions.Like("Name", "%John%"));
        return a.List<Customer>();
Or should I do this with HQL:
        var q = session.CreateQuery("from Customer where " + where);
        return q.List<Customer >();
Or is there a more bether solution?
Thanks for your help.
Best Regards, Thomas
© Stack Overflow or respective owner