Skip to content

Instantly share code, notes, and snippets.

@alecwhittington
Created May 8, 2011 17:30
Show Gist options
  • Save alecwhittington/961524 to your computer and use it in GitHub Desktop.
Save alecwhittington/961524 to your computer and use it in GitHub Desktop.
Sample Implementation of NHQuery
namespace QueryTest.Domain.Contracts.Queries
{
using SharpArch.Domain.PersistenceSupport;
public interface ISampleQuery : IQuery<Address> { }
}
namespace QueryTest.Domain.Contracts.Tasks
{
using System.Collections.Generic;
public interface ISampleTask
{
IList<Address> GetAddressForSample();
}
}
namespace QueryTest.Infrastructure.Queries
{
using System.Collections.Generic;
using System.Linq;
using NHibernate.Linq;
using QueryTest.Domain;
using QueryTest.Domain.Contracts.Queries;
using SharpArch.NHibernate;
public class SampleQuery : NHQuery<Address>, ISampleQuery
{
#region Overrides of NHQuery<Address>
public override IList<Address> ExecuteQuery()
{
return (from a in Session.Query<Address>()
where a.City == "Mesa"
select a).ToList();
}
#endregion
}
}
namespace QueryTest.Tasks
{
using System.Collections.Generic;
using QueryTest.Domain;
using QueryTest.Domain.Contracts.Queries;
using QueryTest.Domain.Contracts.Tasks;
using SharpArch.Domain.PersistenceSupport;
public class SampleTask : ISampleTask
{
private readonly IRepository<Address> addressRepository;
private readonly ISampleQuery sampleQuery;
public SampleTask(IRepository<Address> addressRepository, ISampleQuery sampleQuery)
{
this.addressRepository = addressRepository;
this.sampleQuery = sampleQuery;
}
#region Implementation of ISampleService
public IList<Address> GetAddressForSample()
{
return this.addressRepository.PerformQuery(this.sampleQuery);
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment