DbContext class separated.
This commit is contained in:
20
code/MessengerBroker.Db.Sql/BrokerSqlDbContext.cs
Normal file
20
code/MessengerBroker.Db.Sql/BrokerSqlDbContext.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace MessengerBroker.Db.Sql
|
||||||
|
{
|
||||||
|
public class BrokerSqlDbContext : BrokerDbContext
|
||||||
|
{
|
||||||
|
private readonly string connectionString;
|
||||||
|
|
||||||
|
public BrokerSqlDbContext(string connectionString)
|
||||||
|
{
|
||||||
|
this.connectionString = connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
optionsBuilder.UseSqlServer(this.connectionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
code/MessengerBroker.Db.Sql/MessengerBroker.Db.Sql.csproj
Normal file
17
code/MessengerBroker.Db.Sql/MessengerBroker.Db.Sql.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MessengerBroker.Db\MessengerBroker.Db.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -5,28 +5,10 @@ namespace MessengerBroker.Db
|
|||||||
{
|
{
|
||||||
public class BrokerDbContext : DbContext
|
public class BrokerDbContext : DbContext
|
||||||
{
|
{
|
||||||
private string connectionString;
|
|
||||||
|
|
||||||
public DbSet<Sync> Syncs { get; }
|
public DbSet<Sync> Syncs { get; }
|
||||||
|
|
||||||
public DbSet<User> Users { get; }
|
public DbSet<User> Users { get; }
|
||||||
|
|
||||||
public DbSet<Message> Messages { get; }
|
public DbSet<Message> Messages { get; }
|
||||||
|
|
||||||
public BrokerDbContext(string connectionString)
|
|
||||||
{
|
|
||||||
this.connectionString = connectionString;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
base.OnModelCreating(modelBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
optionsBuilder.UseSqlServer(this.connectionString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
namespace MessengerBroker.Db.Model.Contracts
|
|
||||||
{
|
|
||||||
public interface IForeignEntity
|
|
||||||
{
|
|
||||||
Guid Id { get; }
|
|
||||||
|
|
||||||
Guid BrokerId { get; }
|
|
||||||
|
|
||||||
bool IsDeleted { get; }
|
|
||||||
|
|
||||||
Sync? FirstSync { get; }
|
|
||||||
|
|
||||||
Sync? LastSync { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +1,4 @@
|
|||||||
using MessengerBroker.Db.Model.Contracts;
|
namespace MessengerBroker.Db.Model
|
||||||
|
|
||||||
namespace MessengerBroker.Db.Model
|
|
||||||
{
|
{
|
||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user