Couchbase.EntityFrameworkCore 1.0.0-pre.1

Prefix Reserved
This is a prerelease version of Couchbase.EntityFrameworkCore.
dotnet add package Couchbase.EntityFrameworkCore --version 1.0.0-pre.1                
NuGet\Install-Package Couchbase.EntityFrameworkCore -Version 1.0.0-pre.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Couchbase.EntityFrameworkCore" Version="1.0.0-pre.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Couchbase.EntityFrameworkCore --version 1.0.0-pre.1                
#r "nuget: Couchbase.EntityFrameworkCore, 1.0.0-pre.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Couchbase.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Couchbase.EntityFrameworkCore&version=1.0.0-pre.1&prerelease

// Install Couchbase.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Couchbase.EntityFrameworkCore&version=1.0.0-pre.1&prerelease                

EF Core Couchbase DB Provider

This database provider allows Entity Framework Core to be used with Couchbase Database. The provider is maintained as part of the Couchbase EFCore Project.

It is strongly recommended to familiarize yourself with the Couchbase Database documentation before reading this section. The EF Core Couchbase Db Provider, works with Couchbase Server and Couchbase Capella DBaaS.

[!NOTE] The EF Core Couchbase DB Provider is currently in developer preview and not all code paths work as of the writing of this document.

Install

Install the Couchbase.EntityFrameworkCore NuGet package.

.NET Core CLI or Jet Brains Rider IDE

dotnet add package Couchbase.EntityFrameworkCore

Visual Studio

Install-Package Couchbase.EntityFrameworkCore

Get Started

[!TIP] You can view this article's sample on GitHub

As for other providers the first step is to call UseCouchbase:

protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseCouchbase<INamedBucketProvider>(new ClusterOptions()
                .WithCredentials("Administrator", "password")
                .WithConnectionString("couchbase://localhost"),
            couchbaseDbContextOptions =>
            {
                couchbaseDbContextOptions.Bucket = "OrdersDB";
                couchbaseDbContextOptions.Scope = "_default";
            });

In this example Order is a simple entity with a reference to the owned type StreetAddress.

public class Order
{
    public int Id { get; set; }
    public int? TrackingNumber { get; set; }
    public string PartitionKey { get; set; }
    public StreetAddress ShippingAddress { get; set; }
}
public class StreetAddress
{
    public string Street { get; set; }
    public string City { get; set; }
}

Saving and querying data follows the normal EF pattern:

using (var context = new OrderContext())
{
    await context.Database.EnsureDeletedAsync();
    await context.Database.EnsureCreatedAsync();

    context.Add(
        new Order
        {
            Id = 1, ShippingAddress = new StreetAddress { City = "London", Street = "221 B Baker St" }, PartitionKey = "1"
        });

    await context.SaveChangesAsync();
}

using (var context = new OrderContext())
{
    var order = await context.Orders.FirstAsync();
    Console.WriteLine($"First order will ship to: {order.ShippingAddress.Street}, {order.ShippingAddress.City}");
    Console.WriteLine();
}

Couchbase DB options

There exists options for both the Couchbase SDK which the Couchbase EF Core DB Provider uses and for the provider itself.

What works:

  • Basic projections/queries
  • Some SQL++ functions - COUNT, CONTAINS, etc
  • Basic CRUD and change tracking

What doesn't work

  • Eager Loading
  • Most all SQL++ functions
  • Value generation
  • META, RYOW, etc
  • Lots...it's a WIP

Documentation

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-pre.1 45 10/31/2024