I have a common dapper function to get list<model>
using QueryAsync
of dapper
the function looks like below
public async Task<object> QueryAsync(string spName, DynamicParameters p)
{
return await Task.Run(async () =>
{
object obj = new object();
IList objectList = obj as IList;
using (SqlConnection conn = new SqlConnection(_connStr))
{
try
{
conn.Open();
obj = (List<object>)await conn.QueryAsync<object>(sql: spName, param: p, commandType: CommandType.StoredProcedure);
}
catch (Exception ex)
{
Utils.Logger.Instance.LogException(ex);
}
conn.Close();
}
return obj;
});
}
now I am calling this method from my businessLogic Layer like below
public async Task<List<GetTemplates>> GetDocTemplates(string TemplateName, int AccountId)
{
_Parameters.Add("@SP_TemplateName", TemplateName, dbType: DbType.String, direction: ParameterDirection.Input);
_Parameters.Add("@SP_AccountId", AccountId, dbType: DbType.Int32, direction: ParameterDirection.Input);
return (List<GetTemplates>)await _Dapper.QueryAsync("[dbo].[GetDocTemplates]", _Parameters);
}
but I am getting the following error.
Unable to cast object of type 'System.Collections.Generic.List
1[System.Object]' to type 'System.Collections.Generic.List
1[DocPro.DMS.BusinessEntities.Admin.GetTemplates]'.
I don't know what is wrong with the above code.