gpt4 book ai didi

c# - System.Data.SqlClient.SqlConnection 不包含使用 dapper 和 c# 查询的定义

转载 作者:IT王子 更新时间:2023-10-29 04:42:19 24 4
gpt4 key购买 nike

以下代码在编译时给出如下错误信息:

'System.Data.SqlClient.SqlConnection' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using directive or an assembly reference?)

我已经使用 nuget 打包器添加了 Dapper。

有什么想法吗?谢谢,

代码:

using (SqlConnection sqlConnection = new SqlConnection(Connectionstring))
{
sqlConnection.Open();
Member customer = sqlConnection.Query<Member>("SELECT * FROM member");
return customer;
}

最佳答案

您需要在 .cs 文件中放置一条 using 语句,以使 Dapper 扩展方法可用。

using ...;
using Dapper;
using ...;

关于c# - System.Data.SqlClient.SqlConnection 不包含使用 dapper 和 c# 查询的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com