.NET

Couchbase와 연동되는 3가지 EF Core 통합 기능

5 분 읽기

Couchbase’s new EF Core provider opens the door to some powerful .NET integrations: even ones traditionally tied to relational databases. This post walks through how Identity, GraphQL, and OData all work with Couchbase.

In this post, I’ll walk through three advanced EF Core integrations that I have successfully tested with Couchbase:

  1. ASP.NET Core Identity
  2. GraphQL (via Hot Chocolate)
  3. OData

Note: These integrations are based on limited testing and are not officially supported (yet). Your mileage may vary, but so far, they show a lot of promise.

ASP.NET Core Identity

Microsoft.AspNetCore.Identity.EntityFrameworkCore provides a plug-and-play authentication and user management system for ASP.NET apps.

Couchbase’s EF Core provider works well with it. The only caveat is that you’ll need to make sure the proper collections exist first (like AspNetUsers, AspNetRoles, etc).

Note: You must create the following collections in advance: AspNetUsers, AspNetRoles, AspNetUserRoles, AspNetUserClaims, AspNetUserLogins, AspNetUserTokens, AspNetRoleClaims.

Example EF setup

MVC auth example

Here’s an ASP.NET Core MVC controller with registration, login, and logout, as well as a custom role:

The data follows the standard Identity structure, stored in a Couchbase document. For example, a document in AspNetUser collection:

A document in AspNetUser collection


GraphQL with Hot Chocolate

Hot Chocolate is a popular GraphQL server for .NET. It can integrate with EF Core, leaning on the LINQ capabilities of the provider (which Couchbase has). This means that GraphQL queries are translated to LINQ, which is then translated to Couchbase SQL++.

Setup

Example usage

  • Go to /graphql in browser (this brings up a web interface)

  • Try a query like this:

This will return results like:

Tips

  • GraphQL queries need to match your GSI indexes (it’s just SQL++ queries under the hood).
  • You can use cover indexes and other SQL++ indexes to improve performance.

OData

Microsoft.AspNetCore.OData exposes your EF Core data as OData endpoints, making it easy to connect tools like Excel, Power BI, and Tableau to Couchbase.

Sample program.cs

Controller

Example OData queries

  • https://localhost:7037/odata/Widgets?$filter=price gt 1&$orderby=name
  • https://localhost:7037/odata/Widgets?$select=name,price&$top=10

Note: Make sure your EF Core LINQ queries can be translated to SQL++ and that any filtered/sorted fields are indexed in Couchbase.

Wrapping up

All of these integrations are backed by EF Core—and now, with Couchbase support, you can take full advantage of them in your code. Whether you’re building secure web applications, GraphQL APIs or integrating with BI tools, The EF Core and Couchbase combo makes it possible.

Curious to see more? Let us know what integrations you’d like to explore next!

이 기사 공유하기

작가

Matthew D. Groves is a guy who loves to code. It doesn’t matter if it’s C#, jQuery, or PHP: he’ll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent’s pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.