43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EntityFrameworkBasics
|
|
{
|
|
/// <summary>
|
|
/// The database representational model for application
|
|
/// </summary>
|
|
public class ApplicationDBContext : DbContext
|
|
{
|
|
|
|
#region Public properties
|
|
|
|
public DbSet<SettingsDataModel> Settings { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
/// Default constructor, expecting database options passed in
|
|
/// </summary>
|
|
/// <param name="options">The database context options</param>
|
|
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
|
|
{
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// Fluent Api
|
|
modelBuilder.Entity<SettingsDataModel>().HasIndex(c => c.Name).IsUnique();
|
|
|
|
}
|
|
}
|
|
}
|