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

问题描述 投票:0回答:1

我正在尝试使用 Dapper 连接在 Snowflake 数据库中编写的过程。 每次运行代码时,我都会收到“功能不支持”。在 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;
        }
    }
}
c# .net .net-core snowflake-cloud-data-platform dapper
1个回答
3
投票

无论出于何种原因,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}
);
© www.soinside.com 2019 - 2024. All rights reserved.