.NET Core was released a few months ago, and data access libraries for most databases, both relational and NoSQL are now available. In this post, I’ll detail what client libraries are available, as well as show code samples for each of them.

ORM

EF Core

Entity Framework is Microsoft’s Object-Relational Mapper for .NET, and as such is one of the most-used data access technologies for .NET. EF Core, released simultaneously with .NET Core, is a lightweight and extensible version of Entity Framework that works on both .NET Core and .NET Framework. It has support for Microsoft SQL Server, SQLite, PostgreSQL, MySQL, Microsoft SQL Server Compact Edition, with more, such as DB2 and Oracle, to come.

What follows is an example of EF Core code accessing a blog’s database. The full tutorial can be found on the EF documentation site.

Dapper

Dapper is a micro-ORM built and maintained by StackExchange engineers. It focuses on performance, and can map the results of a query to a strongly-typed list, or to dynamic objects. .NET Core support is available.

NPoco

NPoco is a micro-ORM that also works on .NET Core.

Relational databases

SQL Server

The Microsoft SQL Server client library is built into .NET Core. You don’t have to use an ORM, and can instead go directly to the metal and talk to a SQL Server instance or to an Azure SQL database using the same APIs from the System.Data.SqlClient package.

PostgreSQL

PostgreSQL is an open source relational database with a devoted following. The Npgsql client library supports .NET Core.

Another interesting library for PostgreSQL that is compatible with .NET Core is Marten. Marten uses PostgreSQL storage to implements a document database.

MySQL

MySQL is one of the most commonly used relational databases on the market and is open source. Support for .NET Core is now available, both through EF Core and directly through the MySQL Connector for .NET Core.

SQLite

SQLite is a self-contained, embedded relational database that is released in the public domain. SQLite is lightweight (less than 1MB), cross-platform, and is extremely easy to embed and deploy with an application, which explains how it quietly became the most widely deployed database in the world. It’s commonly used as an application file format.

You can use SQLite with EF Core, or you can talk to a SQLite database directly using the Microsoft.Data.Sqlite library that is maintained by the ASP.NET team.

There’s another SQLite package that’s compatible with .NET Core called SQLitePCL.raw.

Firebird

Firebird is a mature relational database with a small footprint. It now has a .NET Core compatible client library.

NoSQL

Azure DocumentDB

Azure DocumentDB is a NoSQL database service built for fast and predictable performance, high availability, automatic scaling, and ease of development. Its flexible data model, consistent low latencies, and rich query capabilities make it a great fit for web, mobile, gaming, IoT, and many other applications that need seamless scale. Read more in the DocumentDB introduction. DocumentDB databases can now be used as the data store for apps written for MongoDB. Using existing drivers for MongoDB, applications can easily and transparently communicate with DocumentDB, in many cases by simply changing a connection string. The next version of the DocumentDB client library, which will be available around the Connect event, supports .NET Core. The latest version of the DocumentDB SDK supports .NET Core.

MongoDB

MongoDB is a document database with an official .NET driver that supports .NET Core.

RavenDB

RavenDB is a document database that is not only compatible with .NET Core, it’s also built with it.

Redis

Redis is one of the most popular key-value stores.

StackExchange.Redis is a high performance Redis client that is maintained by the StackExchange team.

ServiceStack has its own Redis client library, that is compatible with .NET Core, like the rest of ServiceStack.

Cassandra

Apache Cassandra is a highly scalable and fault-tolerant NoSQL database. DataStax is a C# driver for Cassandra with built-in support for mapping Cassandra data to CLR objects. The latest version is compatible with .NET Core.

CouchBase

CouchBase is an open source document database that is popular in mobile applications. The offical Couchbase client library is compatible with .NET Core.

CouchDB

CouchDB is a document database that I personally like a lot for its simplicity. It can scale from small devices such as a Raspberry Pi to cloud applications. It uses a very simple HTTP and JSON-based API, which limits the need for a client library. C# client libraries do exist, but none of them support .NET Core today as far as I can tell except for Kanapa which hasn’t been updated for a while. It’s very easy to interact with the database through its REST API nonetheless.

Neo4j

Neo4j is a graph database, which means that it establishes relationships not between tables but between data nodes, and treats these relationships as first class semantically rich entities that carry data and can be queried on. Readify has a .NET Core-compatible client for Neo4j called Neo4jClient.

The full sample can be found in Tugberk Ugurlu’s blog post “Getting Started with Neo4j in .NET with Neo4jClient Library”

RethinkDB

RethinkDB is a document database that can stream real-time result updates to a query. RethinkDb.Driver is a .NET Core driver for RethinkDB that covers 100% of the features of the official Java driver. One should exercise caution for new project however, as the company behind RetinkDB is shutting down.

YesSql

YesSql is an interesting library that implements a transactional document database on top of relational stores such as SQL Server.

Lucene.NET

Finally, I want to mention Lucene.NET. It’s not technically a database, but it’s so useful in setting up full-text search on a data-driven project that a post on data access wouldn’t be complete without it. The team has put a lot of work into the new version of Lucene to implement new features and major improvements, and they also made it compatible with .NET Core. It’s still early, but prerelease packages will soon be available.

What about OLE DB?

OLE DB has been a great way to access various data sources in a uniform manner, but it was based on COM, which is a Windows-only technology, and as such was not the best fit for a cross-platform technology such as .NET Core. It is also unsupported in SQL Server versions 2014 and later. For those reasons, OLE DB won’t be supported by .NET Core.

Keeping track

More database support for .NET Core will no doubt become available in the future, and we’ll make sure to highlight new client libraries in our Week in .NET posts as they get announced. In the meantime, I hope this post helps get you started with .NET Core application development.

原文链接:https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/

.NET Core Data Access的更多相关文章

  1. Plugin with data access

    In this tutorial I'll be using the nopCommerce plugin architecture to implement a product view track ...

  2. 【转】深受开发者喜爱的10大Core Data工具和开源库

    http://www.cocoachina.com/ios/20150902/13304.html 在iOS和OSX应用程序中存储和查询数据,Core Data是一个很好的选择.它不仅可以减少内存使用 ...

  3. Cocoa 之 Core Data(2)- 代码示例

    前面详 细讲解了 Core Data 的框架以及设计的类,下面我们来讲解一个完全手动编写代码 使用这些类的示例,这个例子来自 苹果官方示例.在这个例子里面,我们打算做这样一件事 情:记录程序运行记录( ...

  4. DevExpress v18.1新版亮点——Data Access篇

    用户界面套包DevExpress v18.1日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress Data Access v18.1 的新功能,快来下载试用新版本 ...

  5. 在 Core Data 中存取 transformable 类型的数据

    本文转载至 http://imenjoe.com/2015/04/10/CoreData-transformable-20150410/ 在开发过程中有一个需要在 Core Data 中存取 NSDi ...

  6. DevExpress v17.2新版亮点——Data Access

    用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了Data Access v17.2 的新功能,快来下载试用新版本! 新的API可在 ...

  7. iPhone Development – core data relationships tutorial part 1

    I’m going to start a short series on Core Data relationships and maybe throw in some general Core Da ...

  8. Spring.NET的中间数据层(Middle Tier Data Access)——事务管理(Transaction management)

    简介 Spring.NET为事务管理提供了一个持久化抽象(consistent abstraction ),其优点如下: 为不同事务API,例如ADO.NET,Enterprise Services, ...

  9. 深入浅出 Cocoa 之 Core Data(2)- 手动编写代码

    深入浅出 Cocoa 之 Core Data(2)- 代码示例 罗朝辉(http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 前面详细讲解了 Core Data 的框 ...

随机推荐

  1. lintcode-162-矩阵归零

    162-矩阵归零 给定一个m×n矩阵,如果一个元素是0,则将其所在行和列全部元素变成0. 需要在原矩阵上完成操作. 样例 给出一个矩阵 [ [1, 2], [0, 3] ] 返回 [ [0, 2], ...

  2. 【APS.NET Core】- Razor Page 使用jqgrid实现分页功能

    本文将使用jqgrid在Razor Page中实现分页功能. 前台 List.cshtml代码如下: @page @model ListModel @{ Layout = "~/Pages/ ...

  3. 查询MySQL某字段相同值得重复数据

    1.先查询重复的id: SELECT book_id,COUNT(*) AS COUNT FROM xs_book_source WHERE site_id=5 GROUP BY book_id HA ...

  4. 提升MyEclipse运行速度

    修改MyEclipse.ini文件中的,将-vmargs后面的参数修改为 -Xms256m -Xmx768m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:Max ...

  5. 浅析Docker容器的应用场景

    本文来自网易云社区 作者:娄超 过去几年开源界以openstack为代表的云计算持续火了好久,这两年突然又冒出一个叫Docker的容器技术,其发展之迅猛远超预料.网上介绍Docker容器的文章已经很多 ...

  6. 第72天:jQuery实现下拉菜单

    jQuery实现下拉菜单 一.居中 1.块元素居中:给块元素本身设置:margin:0 auto;,块元素必须设置宽度 2.行内块元素居中:给元素父级设置text-algin:center; < ...

  7. Foundation框架—时间处理对象NSDate

    NSDate类用于保存时间值,同时提供了一些方法来处理一些基于秒级别时差(Time Interval)运算和日期之间的早晚比较等. 1. NSDate的构造方法和构造获取实例的属性 用于创建NSDat ...

  8. 【bzoj1727】[Usaco2006 Open]The Milk Queue 挤奶队列 贪心

    题目描述 Every morning, Farmer John's N (1 <= N <= 25,000) cows all line up for milking. In an eff ...

  9. BZOJ4754 JSOI2016独特的树叶(哈希)

    判断两棵无根树是否同构只需要把重心提作根哈希即可.由于只添加了一个叶子,重心的位置几乎不发生偏移,所以直接把两棵树的重心提起来,逐层找哈希值不同且对应的两子树即可.被一个普及组子问题卡一年. #inc ...

  10. 【刷题】BZOJ 1717 [Usaco2006 Dec]Milk Patterns 产奶的模式

    Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". ...