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

查看:154
本文介绍了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派生一个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.

在快速的Google搜索之后,我发现了这些项目,这些项目可能现在可以为您提供帮助...

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..

  • https://github.com/dotnet/corefx/issues/13035
  • https://github.com/aspnet/EntityFramework/issues/7432

更新6/23/2017:

现在可以通过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天全站免登陆