Reputation: 419
I have a really big problem: I am trying to find Entities (with NHibernate) using other object. Example: Emplyee (entity) -> { Name, LastName, Email, Address } EmplyeeSearchFilters (filters object) -> { Name, LastName, Email, Address } Then, I want to pass EmployeeSearchFilters to the Repository (generic) and automatically find with NHibernate using the properties that are not null. Example: EmployeeSearchFilters -> { Name = "Nelly", LastName = null, Email = "@fibertel.com", Addres = null } Someone have idea how can I do that?
Thanks!
Upvotes: 0
Views: 399
Reputation: 593
You can use linq by use this function:
public virtual List<T> RetrieveByList<T>(Expression<Func<T, bool>> predicate)
{
return Session.Query<T>().Where(predicate).ToList<T>();
}
and can use like this:
RetrieveByList<Customer>(x=>x.Name == "Nelly" && x.LastName == null && x.Email == "@fibertel.com" && x.Addres == null)
and you can use with dynamic predicate http://www.codeproject.com/Articles/28580/LINQ-and-Dynamic-Predicate-Construction-at-Runtime
Upvotes: 1