Im trying to make a generic Find method with DapperExtensions
This is my method
public IEnumerable<T> Find(Expression<Func<T, object>> expression)
{
using (IDbConnection cn = GetCn())
{
cn.Open();
var predicate = Predicates.Field<T>(expression, Operator.Eq, true);
return cn.GetList<T>(predicate);
}
}
But i get System.NullReferenceException
on this row var predicate = Predicates.Field<T>(expression, Operator.Eq, true);
This is from the DapperExtensions help documentation But I try convert this to a Generic method.
using (SqlConnection cn = new SqlConnection(_connectionString))
{
cn.Open();
var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true);
IEnumerable<Person> list = cn.GetList<Person>(predicate);
cn.Close();
}
Func<T,bool>
, where-as yours isFunc<T,object>
- that is the most obvious difference I can see... – Marc Gravell♦ Jan 30 '13 at 8:00