public Task<ContentModel> GetModelAsync(int id)
{
using (Conn)
{
string categoryTable = tbPrefix + "Category";
string userTable = tbPrefix + "User";
string sql ="select * from " + tb + " a join " + categoryTable + " b on a.categoryid=b.id join (select id,nickname,avatar from " + userTable + ") c on a.userid=c.id where a.id=@id";
return Conn.QueryAsync<ContentModel, CategoryModel, UserModel, ContentModel>(sql, (a, b, c) => { a.category = b; a.user = c; return a; }, new { id = id });
}
}
红色里怎么写?
var result = await conn.QueryFirstAsync<ContentModel>(sql,new { id = id });
return result.ToList();
同步有这个方法:Conn.Query<ContentModel, CategoryModel, UserModel, ContentModel>(sql, (a, b, c) => { a.category = b; a.user = c; return a; }, new { id = id });
但是异步就报错。Conn.QueryAsync<ContentModel, CategoryModel, UserModel, ContentModel>(sql, (a, b, c) => { a.category = b; a.user = c; return a; }, new { id = id })
错误 CS1061 '“IDbConnection”未包含“QueryAsync”的定义,并且找不到可接受第一个“IDbConnection”类型参数的可访问扩展方法“QueryAsync”(是否缺少 using 指令或程序集引用?)
官网只翻到QueryAsync<T>实例,但是没有QueryAsync<T1,T2,T3,T4>多个参数的实例。