.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

참고: 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).

참고: 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

참고: 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!

이 기사 공유하기

작가

매튜 D. 그로브스는 코딩을 정말 좋아하는 사람입니다. C#, jQuery, PHP 등 어떤 언어든 상관없이, 그는 무엇이든 풀 리퀘스트를 제출합니다. 그는 90년대에 부모님이 운영하던 피자 가게를 위해 QuickBASIC으로 POS(판매 시점 관리) 앱을 개발한 이래로 줄곧 전문 프로그래머로 활동해 왔습니다. 현재는 Couchbase에서 선임 제품 마케팅 매니저로 근무하고 있습니다. 여가 시간에는 가족과 함께 시간을 보내거나, 레즈(Reds) 경기를 관람하며, 개발자 커뮤니티 활동에 참여합니다. 그는 『AOP in .NET』과 『Pro Microservices in .NET』의 저자이자 Pluralsight 저자이며, Microsoft MVP이기도 합니다.

댓글 남기기

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

개발 시작하기

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

카펠라 프리 사용하기

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

연락해

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