31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using MessengerApi.Db.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MessengerApi.Db.Sql
|
|
{
|
|
public class MessengerSqlDbContext : MessengerDbContext
|
|
{
|
|
private readonly string connectionString;
|
|
|
|
public MessengerSqlDbContext(string connectionString)
|
|
{
|
|
this.connectionString = connectionString;
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
base.OnConfiguring(optionsBuilder);
|
|
optionsBuilder.UseSqlServer(this.connectionString);
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// https://stackoverflow.com/questions/26464357/what-is-the-purpose-of-non-unique-indexes-in-a-database
|
|
// https://stackoverflow.com/questions/40767980/generate-a-composite-unique-constraint-index-in-ef-core
|
|
// https://www.geeksforgeeks.org/difference-between-clustered-and-non-clustered-index/
|
|
modelBuilder.Entity<Message>().HasIndex(e => new { e.ToId, e.IsDelivered }).IsUnique(false).IsClustered(false);
|
|
}
|
|
}
|
|
} |