SqlServerBuilderExtensions.AddDatabase Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a SQL Server database to the application model. This is a child resource of a SqlServerServerResource.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SqlServerDatabaseResource> AddDatabase(this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SqlServerServerResource> builder, string name, string? databaseName = default);
static member AddDatabase : Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SqlServerServerResource> * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.SqlServerDatabaseResource>
<Extension()>
Public Function AddDatabase (builder As IResourceBuilder(Of SqlServerServerResource), name As String, Optional databaseName As String = Nothing) As IResourceBuilder(Of SqlServerDatabaseResource)
Parameters
- builder
- IResourceBuilder<SqlServerServerResource>
The SQL Server resource builders.
- name
- String
The name of the resource. This name will be used as the connection string name when referenced in a dependency.
- databaseName
- String
The name of the database. If not provided, this defaults to the same value as name.
Returns
A reference to the IResourceBuilder<T>.
Remarks
When adding a SqlServerDatabaseResource to your application model the resource can then be referenced by other resources using the resource name. When the dependent resource is using the extension method WaitFor<T>(IResourceBuilder<T>, IResourceBuilder<IResource>) then the dependent resource will wait until the SQL Server database is available.
Note that calling AddDatabase(IResourceBuilder<SqlServerServerResource>, String, String) will result in the database being created on the SQL Server when the server becomes ready. The database creation happens automatically as part of the resource lifecycle.