3 Using Database and Storage Components

 

This chapter covers

  • Connecting .NET Aspire to an existing database instance using connection strings.
  • Integrating SQL Server and consuming it with both raw SQL and Entity Framework.
  • Working with other relational databases, including Oracle, PostgreSQL, and MySQL.
  • Using NoSQL databases such as MongoDB and Azure Cosmos DB.
  • Connecting to Azure Storage services like Table Storage and Blob Storage.

.NET Aspire can be integrated with any database types, including both SQL-based relational database management systems (RDBMS) and various categories of NoSQL databases, such as document stores, key-value stores, etc. All of this can be done via .NET Aspire integration libraries.

In this chapter, we will cover both database categories with examples showing a range of specific data storage technologies in both SQL and NoSQL areas. However, before we start, let’s talk about connecting .NET Aspire to an existing database instance.

3.1 Connecting .NET Aspire to an existing database

Before we look at how to build database resources and let the .NET Aspire host manage them, we will look at how to connect Aspire instances to the existing resources. After all, you may already have a fully managed instance of a SQL Server, Oracle, or MongoDB database that you want to connect your system to.

3.2 SQL Database components basics

3.3 Hosting an SQL Server component

3.3.1 Consuming an SQL Server integration

3.3.2 Using Entity Framework

3.3.3 Integrating with Azure SQL Server

3.4 Hosting an Oracle component

3.4.1 Oracle client integration

3.5 Hosting a PostgreSQL component

3.5.1 PostgreSQL client integrations

3.6 Hosting a MySQL component

3.6.1 MySQL client integration

3.7 Introduction to NoSQL

3.8 Hosting a MongoDB component

3.8.1 Introduction to MongoDB

3.8.2 Hosting a MongoDB component

3.8.3 Working with a MongoDB client

3.9 Working with Azure Cosmos DB

3.9.1 Cosmos DB overview

3.9.2 Hosting a Cosmos DB component

3.9.3 Connecting to Cosmos DB

3.9.4 Registering CosmosDB and the background service

3.9.5 Returning data from an API endpoint

3.10 Azure Table Storage integration

3.10.1 Hosting Azure Storage component

3.10.2 Interacting with Azure Table Storage

3.11 Integrating with Azure Blob Storage

3.11.1 Interacting with Azure Blob Storage

3.12 Summary