I've been using dapper lately and wanted to make a dynamic method that would make it easier to select things out with sql. This is my code:
Class:
public class Method
{
public static IEnumerable<dynamic> QueryAll(string table)
{
dynamic dyn = table;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DbCon"].ToString());
using (con)
{
string sql = String.Format("SELECT * FROM {0}", table);
IEnumerable<dynamic> ie = con.Query<dynamic>(sql, null);
return ie;
}
}
}
Calling function here:
IEnumerable<posts> = Method.QueryAll("posts");
It gives me an error that I cannot convert IEnumerable dynamic to IEnumerable Models.Posts
.
How can I cast it to make it work.