I'm using a combination of NHibernate and LINQ to try and achieve queries, but I'm worried the following query is pulling back every single user row from the DB, giving a large DB latency, large network traffic, large memory footprint, then filtering it out far too late.
public bool CheckEmailAddressIsAvailable
(string emailAddress, IDataRepository repository)
{
var users = from user in repository.GetItems<User>()
where user.EmailAddress.Equals(
emailAddress,
System.StringComparison.CurrentCultureIgnoreCase)
select user;
return !(users.Any());
}
DataRepository is a simple wrapper around NHibernate Session What I want to know is twofold
1) How can I log all NHibernate SQL that is being created so I can keep an eye on what is being run and 2) How can I run the above query to mimic the below SQL
select count(*) from [User] where EmailAddress = @emailAddress