首页 新闻 搜索 专区 学院

dapper.net 异步多表查询

0
悬赏园豆:5 [已解决问题] 解决于 2020-01-01 12:42

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 });

}
}

 

红色里怎么写?

DZCMS的主页 DZCMS | 初学一级 | 园豆:5
提问于:2019-12-29 12:30
< >
分享
最佳答案
0

var result = await conn.QueryFirstAsync<ContentModel>(sql,new { id = id });
return result.ToList();

收获园豆:5
初夏的阳光丶 | 小虾三级 |园豆:571 | 2019-12-30 16:28

同步有这个方法: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>多个参数的实例。

DZCMS | 园豆:5 (初学一级) | 2020-01-01 10:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册