I'm using FluentData as an orm for my database and I'm trying to create a generic query method:
internal static T QueryObject<T>(string sql, object[] param, Func<dynamic, T> mapper)
{
return MyDb.Sql(sql, param).QueryNoAutoMap<T>(mapper).FirstOrDefault();
}
Except in my class's function:
public class MyDbObject
{
public int Id { get; set; }
}
public static MyDbObject mapper(dynamic row)
{
return new MyDbObject {
Id = row.Id
};
}
public static MyDbObject GetDbObjectFromTable(int id)
{
string sql = @"SELECT Id FROM MyTable WHERE Id=@Id";
dynamic param = new {Id = id};
return Query<MyDbObject>(sql, param, mapper);
}
at Query<MyDbObject>(sql, param, mapper)
the compilers says:
An anonymous function or method group connot be used as a constituent value of a dynamically bound object.
Anyone have an idea of what this means?
Edit:
The compiler doesn't complain when I convert the method into a delegate:
public static Func<dynamic, MyDbObject> TableToMyDbObject =
(row) => new MyDbObject
{
Id = row.Id
}
It still begs the question of why one way is valid but not the other.