AWS RedShift - .NET Core(ODBC 支持?) [英] AWS RedShift - .NET Core (ODBC Support?)

查看:29
本文介绍了AWS RedShift - .NET Core(ODBC 支持?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 .NET Core 连接和运行针对 AWS RedShift 的查询?请提供代码示例.我已经阅读了 AWS 文档和 .Net Core 文档,但没有成功.

How can I connect and run queries against AWS RedShift using .NET Core? Code sample please. I have gone through the AWS docs and .Net Core docs but no luck.

推荐答案

这个答案是针对特定时间点的,不会过时...

This answer is one for a particular point in time and won't age well...

EntityFramework Core 项目是我最关注的项目.缺少 ODBC 是众所周知的,特别是对于那些想要连接到 Oracle 的人.目前,您可能需要为 .NET Core fork 一个 Oracle 客户端并根据需要进行修改.

The EntityFramework Core project is the one I'd keep the closest eye on. The lack of ODBC is well known, especially for those who want to connect to Oracle. For the time being, you may need to fork an Oracle client for .NET core and make modifications as necessary.

我在谷歌快速搜索后找到了这些项目,现在可能对你有帮助......

I found these projects after a quick Google search that may be able to help you for now...

- https://github.com/LinqDan/oracleclientcore- https://github.com/LinqDan/Mono.Data.OdbcCore

从长远来看,您需要关注这两个 GitHub 问题,它们正在为 EntityFramework Core 和 .NETStandard API 跟踪它..

Longer term, you'll want to keep an eye on these two GitHub issues which are tracking it for EntityFramework Core and the .NETStandard APIs..

2017 年 6 月 23 日更新:

这现在可以通过 Npgsql.EntityFrameworkCore.PostgreSQL NuGet 包和关联的 Entity Framework Core 包实现.显然,PostgreSQL 团队已经厌倦了等待 ODBC 支持(在最新的 netstandard2.0 中仍然不可用)并使用 netstandard 编写了他们自己的驱动程序 - 早在 11 月的时间范围内.npgsql 网站上的 入门 页面涵盖了它在旧 JSON 项目格式中的用法 - 但是列出的依赖项仍然有效.

This is now possible through the Npgsql.EntityFrameworkCore.PostgreSQL NuGet package and associated Entity Framework Core packages. Apparently the PostgreSQL team was tired of waiting around for ODBC support (which still isn't available in the latest netstandard2.0 yet) and wrote their own driver using netstandard - back in the November timeframe. The getting started page on the npgsql website covers it's usage in the old JSON project format - but the dependencies listed are still valid.

这是您将如何使用该软件包...

Here is how you would use the package...

using (var conn = new NpgsqlConnection("Host=myserver;Username=mylogin;Password=******;Database=music"))
{
    conn.Open();
    using (var cmd = new NpgsqlCommand())
    {
        cmd.Connection = conn;

        cmd.CommandText = "SELECT name FROM artists";
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
        }
    }
}

使用此驱动程序时要记住的一件事 - 它是为 PostgreSQL 而不是 Redshift 编写的.虽然 Redshift 基于 PostgreSQL,但它的底层引擎更像是 Cassandra.因此,亚马逊不得不在开发中做出一些选择,以放弃 PostgreSQL 支持的某些东西——例如 SQL 变量.因此,对于在其他实体框架实现中可能习惯的某些事情,您将获得相当有限的体验.只要您继续使用直接访问 *Connection、*Command 和 DataReader 类并编写自己的 SQL,就可以了.

One thing to keep in mind when using this driver - it's written for PostgreSQL, not Redshift. While Redshift is based on PostgreSQL, it's underlying engine is much more like Cassandra than anything else. As a result, Amazon had to make some choices in the development to drop certain things that PostgreSQL does support - such as SQL variables. Because of this, you will have a fairly limiting experience for certain things that you might be used to in other Entity Framework implementations. As long as you stay with using the direct access *Connection, *Command, and DataReader classes and write your own SQL, you should be fine.

这篇关于AWS RedShift - .NET Core(ODBC 支持?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆