---
title: Getting Started with Couchbase EFCore
description: Get up and running with <code>Couchbase.EntityFrameworkCore</code>
  via a Console application.
pubDate: 2026-08-17T09:53:44.266Z
antora:
  editUrl: https://github.com/couchbase/docs-efcore/edit/release/1.0/modules/ROOT/pages/start-using-efcore-provider.adoc
  xref: xref:efcore-provider::start-using-efcore-provider.adoc[]
---

[Consult the llms.txt file for a full list of contents](/llms.txt)
[View original HTML](/efcore-provider/current/start-using-efcore-provider.html)

# Getting Started with Couchbase EFCore

> Get up and running with `Couchbase.EntityFrameworkCore` via a Console application. 

The Contoso University sample application is also a great way to become familier with the provider.

> [!NOTE]
> This is a clone of the [EFGettingStarted](https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app) example in the MS Docs.

## [](#prerequisites)Prerequisites

* Download and Install [.NET 8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
* Create a [Couchbase Capella](https://docs.couchbase.com/cloud/get-started/create-account.html) free tier account.

## [](#create-the-couchbase-capella-database)Create the Couchbase Capella database

> [!TIP]
> Checkout this [blog](https://jeffrymorris.net/2024/12/07/getting-started-with-ef-core-couchbase-db-provider/) for details on how to set up the Couchbase Capella database for this example.

After you have created your [Couchbase Capella](https://docs.couchbase.com/cloud/get-started/create-account.html) free tier, you must create a [Cluster](../../server/current/learn/clusters-and-availability/clusters-and-availability.md#clusters), a [Bucket](../../server/current/learn/buckets-memory-and-storage/buckets.md) named "Content", a [Scope](../../server/current/learn/data/scopes-and-collections.md) named "Blogs", and then [Collections](../../server/current/learn/data/scopes-and-collections.md) called "Blog" and "Post" for storing the documents. Note that names are **case-sensitive**.

## [](#create-a-console-application)Create a Console application

* Create the .NET Console Application using [this tutorial](https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code?pivots=dotnet-8-0)or [Visual Studio](https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-8-0)or via the [Command Line](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new):  
```console  
mkdir CouchbaseGettingStarted  
cd CouchbaseGettingStarted  
dotnet new console  
```
* Once you have created the console application add the dependency on `Couchbase.EntityFrameworkCore`:  
```console  
dotnet install Couchbase.EntityFrameworkCore --version 1.0.0  
```
* Add the dependency on `EFCore.NamingConventions`:  
```console  
dotnet install EFCore.NamingConventions --version 8.0.3  
```

> [!NOTE]
> The `EFCore.NamingConventions` package is used to enforce the casing of the SQL++ statements generated by EF Core. The default casing for the SQL generated by EF Core is PascalCase, which doesn't match the JSON CamelCase convention used by the Couchbase SDK. If the two do not match, results will be returned, but the values will be the .NET defaults for each respective property type.

* In the project directory, create Model.cs with the following code:  
```csharp  
using Microsoft.EntityFrameworkCore;  
using Couchbase;  
using Couchbase.EntityFrameworkCore;  
using Couchbase.EntityFrameworkCore.Extensions;  
using Couchbase.Extensions.DependencyInjection;  
using Microsoft.Extensions.Logging;  
using Microsoft.Extensions.Logging.Console;  
public class BloggingContext : DbContext  
{  
    public DbSet<Blog> Blogs { get; set; }  
    public DbSet<Post> Posts { get; set; }  
    protected override void OnConfiguring(DbContextOptionsBuilder options)  
    {  
        var loggingFactory = LoggerFactory.Create(builder => builder.AddConsole());  
        options.UseCouchbase(  
            new ClusterOptions()  
                .WithCredentials("USERNAME", "PASSWORD")  
                .WithConnectionString("couchbases://cb.xxxxxxxx.cloud.couchbase.com")  
                .WithLogging(loggingFactory),  
            couchbaseDbContextOptions =>  
            {  
                couchbaseDbContextOptions.Bucket = "Content";  
                couchbaseDbContextOptions.Scope = "Blogs";  
            });  
            options.UseCamelCaseNamingConvention(); // Use EFCore.NamingConventions for JSON document casing  
    }  
    protected override void OnModelCreating(ModelBuilder modelBuilder)  
    {  
        modelBuilder.Entity<Blog>().ToCouchbaseCollection(this, "Blog");  
        modelBuilder.Entity<Post>().ToCouchbaseCollection(this, "Post");  
    }  
}  
public class Blog  
{  
    public string BlogId { get; set; }  
    public string Url { get; set; }  
    public List<Post> Posts { get; } = new();  
}  
public class Post  
{  
    public string PostId { get; set; }  
    public string Title { get; set; }  
    public string Content { get; set; }  
    public int BlogId { get; set; }  
    public Blog Blog { get; set; }  
}  
```

## [](#create-read-update-delete)Create, read, update & delete

* Open _Program.cs_ and replace the contents with the following code  
```csharp  
using var db = new BloggingContext();  
// Note: This sample requires the Couchbase database to be created before running.  
// The Bucket name is "Content", the scope is "Blogs" and the collections are "Post and "Blog"  
// Buckets, Scopes and Collections are case sensitive!  
// Create  
Console.WriteLine("Inserting a new blog");  
var blog = new Blog  
{  
    Url = "http://blogs.msdn.com/adonet",  
    BlogId = Guid.NewGuid().ToString()  
};  
db.Add(blog);  
await db.SaveChangesAsync();  
// Read  
Console.WriteLine("Querying for a blog");  
blog = await db.Blogs  
    .OrderBy(b => b.BlogId)  
    .FirstAsync();  
// Update  
Console.WriteLine("Updating the blog and adding a post");  
blog.Url = "https://devblogs.microsoft.com/dotnet";  
blog.Posts.Add(  
    new Post  
    {  
        Title = "Hello World",  
        Content = "I wrote an app using EF Core!",  
        PostId = Guid.NewGuid().ToString()  
    });  
await db.SaveChangesAsync();  
// Delete  
Console.WriteLine("Delete the blog");  
db.Remove(blog);  
await db.SaveChangesAsync();  
```

## [](#run-the-app)Run the app

* _Run 'CouchbaseGettingStarted'_ in Rider IDE Or,
* _Debug > Start Without Debugging_ in VS Or,
* `dotnet run` in .NET CLI  
```console  
/source/couchbase-dotnet-ef/samples/CouchbaseGettingStarted/bin/Debug/net8.0/CouchbaseGettingStarted  
Inserting a new blog  
Querying for a blog  
Updating the blog and adding a post  
Delete the blog  
Process finished with exit code 0.  
```