Skip to content

Commit

Permalink
Merge pull request #29 from couchbaselabs/contoso-update
Browse files Browse the repository at this point in the history
Update Contoso app to use Capella
  • Loading branch information
jeffrymorris authored Dec 9, 2024
2 parents 4ef474c + 50fa9c5 commit 3ea6603
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
18 changes: 8 additions & 10 deletions docs/contoso-sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ This the sample app that is included in the [Tutorial: Get started with EF Core
## Prerequisites
* Requires [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) to build
* Setup Couchbase Server:
* Works best with [Couchbase Server 7.6.0](https://www.couchbase.com/downloads/?family=couchbase-server#) or better. If you chose to use an earlier Couchbase version you will manually need to add the indexes, which can be quite time consuming - OR-
* [Couchbase Capella ](https://www.couchbase.com/downloads/?family=capella) Cloud also works and has a free-tier that makes it easy to get up and running. Refer to the [documentation](https://docs.couchbase.com/home/cloud.html) for getting up and running with Capella -OR-
* A Couchbase [docker image](https://docs.couchbase.com/server/current/install/getting-started-docker.html) may also be used.
* [Couchbase Capella ](https://www.couchbase.com/downloads/?family=capella) Cloud has a [free-tier](https://docs.couchbase.com/cloud/get-started/create-account.html#sign-up-free-tier) that makes it easy to get up and running.
* Refer to the [documentation](https://docs.couchbase.com/home/cloud.html) for getting up and running with Capella

## Create the Couchbase Server Bucket

Couchbase Server uses Buckets in place of RDBMS database instances. For the Contoso University app, we will create a Bucket named "universities":
Couchbase Server uses Buckets in place of RDBMS database instances. For the Contoso University app, we will create a Bucket named "Universities" with a Scope named "Contoso" and a Collection named "Course":

![img_6.png](img_6.png)
![img_14.png](img_14.png)

In Couchbase, a Scope is an example of a tenant. For the Contoso University application, we will create a Scope named "contoso":
Finally, we will create Collections for each entity in the Contoso model under the "Contoso" Scope (Course, CourseAssignment, Department, Enrollment, OfficeAssignment and Person):

![img_7.png](img_7.png)
![img_15.png](img_15.png)

Finally, we will create Collections for each entity in the Contoso model:

![img_8.png](img_8.png)
> [!NOTE]
> All names are **case-sensitive** from the Bucket to the Scope and Collection names.
When the application loads, it will generate the documents for the model and store them in the Bucket.

Expand Down
Binary file added docs/img_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions samples/ContosoUniversity/Data/SchoolContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>().ToCouchbaseCollection("course");
modelBuilder.Entity<Enrollment>().ToCouchbaseCollection("enrollment");
modelBuilder.Entity<Student>().ToCouchbaseCollection("person");
modelBuilder.Entity<Instructor>().ToCouchbaseCollection("person");
modelBuilder.Entity<Person>().ToCouchbaseCollection("person");
modelBuilder.Entity<Department>().ToCouchbaseCollection("department");
modelBuilder.Entity<OfficeAssignment>().ToCouchbaseCollection("officeAssignment");
modelBuilder.Entity<CourseAssignment>().ToCouchbaseCollection("courseAssignment");
modelBuilder.Entity<Course>().ToCouchbaseCollection("Course");
modelBuilder.Entity<Enrollment>().ToCouchbaseCollection("Enrollment");
modelBuilder.Entity<Student>().ToCouchbaseCollection("Person");
modelBuilder.Entity<Instructor>().ToCouchbaseCollection("Person");
modelBuilder.Entity<Person>().ToCouchbaseCollection("Person");
modelBuilder.Entity<Department>().ToCouchbaseCollection("Department");
modelBuilder.Entity<OfficeAssignment>().ToCouchbaseCollection("OfficeAssignment");
modelBuilder.Entity<CourseAssignment>().ToCouchbaseCollection("CourseAssignment");
modelBuilder.Entity<CourseAssignment>()
.HasKey(c => new { c.CourseID, c.InstructorID });
}
Expand Down
8 changes: 4 additions & 4 deletions samples/ContosoUniversity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

builder.Services.AddDbContext<SchoolContext>(options=> options
.UseCouchbase<INamedBucketProvider>(new ClusterOptions()
.WithCredentials("Administrator", "password")
.WithConnectionString("couchbase://localhost"),
.WithCredentials("Ajax", "GE9jk9i28L2Psg@")
.WithConnectionString("couchbases://cb.umolxgoqkdzpvdvo.cloud.couchbase.com"),
couchbaseDbContextOptions =>
{
couchbaseDbContextOptions.Bucket = "universities";
couchbaseDbContextOptions.Scope = "contoso";
couchbaseDbContextOptions.Bucket = "Universities";
couchbaseDbContextOptions.Scope = "Contoso";
}));


Expand Down

0 comments on commit 3ea6603

Please sign in to comment.