views:

388

answers:

3

I have read the very good blog post of Rob Conery Crazy Talk: Reducing ORM Friction
How can I generalize this interface so I can implement it with NHibernate?

using System;  
using System.Collections;  
using System.Linq;  
using System.Linq.Expressions;   


public interface IRepository<T>   
{  
     IQueryable<T> GetAll();  
     PagedList<T> GetPaged(int pageIndex, int pageSize);  
     IQueryable<T> Find(Expression<Func<T, bool>> expression);  
     void Save(T item);  
     void Delete(T item);  
}

I want to use the Expression<Func<T, bool>> expression in NHibernate. Any clue?

A: 

You'll need to walk the expression tree and build your Criteria.

jonnii
+3  A: 

Look at LINQ to NHibernate. Kyle Baley has a great overview of it

Ryan Rinaldi
+1  A: 

See this question, it's very similar and it already has the relevant answers.

Mauricio Scheffer