Couchbase.EntityFrameworkCore
1.0.0-pre.1
Prefix Reserved
dotnet add package Couchbase.EntityFrameworkCore --version 1.0.0-pre.1
NuGet\Install-Package Couchbase.EntityFrameworkCore -Version 1.0.0-pre.1
<PackageReference Include="Couchbase.EntityFrameworkCore" Version="1.0.0-pre.1" />
paket add Couchbase.EntityFrameworkCore --version 1.0.0-pre.1
#r "nuget: Couchbase.EntityFrameworkCore, 1.0.0-pre.1"
// 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();
}
- The Contoso University web app code
- Contoso University sample documentation
- Getting started - in more detail
Couchbase DB options
There exists options for both the Couchbase SDK which the Couchbase EF Core DB Provider uses and for the provider itself.
- ClusterOptions settings
- Couchbase EF Core DB Provider settings
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 | Versions 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. |
-
net8.0
- Couchbase.Extensions.DependencyInjection (>= 3.6.3)
- CouchbaseNetClient (>= 3.6.3)
- Microsoft.EntityFrameworkCore (>= 8.0.8)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.8)
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 | 1,254 | 10/31/2024 |