// Copyright (c) Microsoft. All rights reserved.
using System.Data.Entity;
using Microsoft.Extensions.Configuration;
namespace StructuredDataPlugin;
///
/// Represents a database context for the structured data plugin demo.
/// Inherits from Entity Framework's DbContext to provide database access and management.
///
internal sealed class ApplicationDbContext : DbContext
{
///
/// Initializes a new instance of the class using configuration settings.
///
/// The configuration object containing connection string information.
///
/// The connection string is retrieved from the configuration using the pattern "ConnectionStrings:ApplicationDbContext".
///
public ApplicationDbContext(IConfiguration config) :
base(config[$"ConnectionStrings:{nameof(ApplicationDbContext)}"]!)
{
}
///
/// Initializes a new instance of the class using a direct connection string.
///
/// The connection string to the database.
public ApplicationDbContext(string connectionString)
: base(connectionString)
{
}
///
/// Configures the database model and its relationships.
///
/// The builder being used to construct the model for this context.
///
/// This method:
/// - Disables database initialization
/// - Maps the Product entity to the "Products" table
/// - Calls the base configuration
///
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(null);
modelBuilder.Entity().ToTable("Products");
base.OnModelCreating(modelBuilder);
}
}