I'm building a repository layer for nhibernate, in which I have the following find method:
public IList<TEntity> Find(Expression<Func<TEntity, bool>> query)
I would like to add a condition to the query in that method. The extra condition should limit rows to all where RemovedAt is larger than DateTime.Now.
Explanation using SQL:
Let's assume that I have the following SQL query:
SELECT * FROM users WHERE first_name LIKE 'a%' OR last_name LIKE 'a%'
It would look like this after the modification:
SELECT * FROM users WHERE (first_name LIKE 'a%' OR last_name LIKE 'a%') AND created_at > '2010-09-22 19:31'
Can it be done on the linq query, or in nhibernate?
Edit
Sorry, forgot to mention that all entities do not have a RemovedAt method. The interface is declared as:
public interface IRepository<TEntity, TKey> where TEntity : class, new()
I'm changing CreatedAt/RemovedAt/UpdatedAt (in their respective methods) by looking for a property with that name and using reflection to update the value.