.net 如何使用Dapper将C#连接到Snowflake?

pcww981p  于 2023-03-20  发布在  .NET
关注(0)|答案(1)|浏览(162)

我正在尝试使用Dapper连接Snowflake数据库中编写的过程。每次运行代码时,我都会得到不支持的功能在www.example.com中使用相同的存储过程ADO.net,它工作正常。
下面是我正在使用的代码

public async Task<IEnumerable<TestClass>> GetTestData()
        {
            IEnumerable<TestClass> response = new List<TestClass>();

            using (IDbConnection dbConnection = this.databaseConnection.GetSnowConnection())
            {

                IEnumerable<TestClass> result = new List<TestClass>();

                try
                {
                    result = await dbConnection.QueryAsync<TestClass>("CALL TESTSP1", commandType: CommandType.StoredProcedure, commandTimeout: 0);

                    response = response.Concat(result);
                    return response;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }`
wz8daaqr

wz8daaqr1#

看起来不管什么原因,Snowflake都不支持CommandType.StoredProcedure。顺便说一句,如果你打算使用它,那么你会去掉CALL部分。
只需使用默认值CommandType.Text即可

result = await dbConnection.QueryAsync<TestClass>("CALL TESTSP1", commandTimeout: 0);

或者使用参数(Dapper可以从对象中推断出它们)

result = await dbConnection.QueryAsync<TestClass>(
    "CALL TESTSP1(:Value1, :Value2)",
    commandTimeout: 0,
    params: new {Value1, Value2}
);

相关问题