I have a 'Customer' table with 'FirstName' and 'LastName' columns. I have to execute a search on the 'Customer' table after 'FirstName', 'LastName' and 'FirstName + LastName' depending on a TextBox text. What's the besty way/query to implement this using NHibernate or SQL query?
A:
using HQl that would be simple
var session = SessionFactory.OpenSession;
var transaction = session.BeginTransaction;
var query = session.CreateQuery("FROM Customer c WHERE c.LastName = :LastName And c.FirstName = :FirstName");
query.SetString("FirstName", FirstName);
query.SetString("LastName", LastName);
var returnList = _Query.List(Of Customer)();
transaction.Commit();
Of course that is presumming that you have an object called Customer and that it is mapped correctly.
chrissie1
2009-06-09 06:42:13