using Castle.ActiveRecord; using Castle.ActiveRecord.Framework; using Castle.ActiveRecord.Queries; using NHibernate; using NHibernate.Expression; using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Text; namespace Northwind.DataAccess.Query { /// <summary> /// This class is a variation of <see>ExampleQuery</see> and passes a name pattern to the hql query. /// </summary> public class FetchCustomerByNameQuery : ActiveRecordBaseQuery { string name = ""; public FetchCustomerByNameQuery(string name) : base(typeof(ActiveRecordBase)) { this.name = name; } protected override IQuery CreateQuery(ISession session) { string hqlFrom = string.Format("from {0} obj ", typeof(Northwind.Domain.Model.Customer).Name); string hqlWhere = "where obj.CompanyName like :name"; //creating the query IQuery q = session.CreateQuery(hqlFrom + " " + hqlWhere); q.SetString("name", "%" + name + "%"); return q; } protected override object InternalExecute(ISession session) { IQuery q = CreateQuery(session); return SupportingUtils.BuildArray(typeof(Northwind.Domain.Model.Customer), q.List()); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)