/
WorkerTime
/
WorkerTimeDiplom
Обзор
Документация
Войти
/
WorkerTime
/
WorkerTimeDiplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
AppDbContext.cs
44 строки
1 KB
nikit
Логирование, автосохранение, восстановление пароля
05 июн 2026, 19:24
05 июн 2026, 19:24
715eb3d
Код
Авторство
О чём код?
using Microsoft.EntityFrameworkCore; using System.IO; using System.Collections.Generic; using System.Reflection.Emit; namespace WorkerTime { public class AppDbContext : DbContext { //Таблицы public DbSet<Employee> Employees { get; set; } public DbSet<WorkRecord> WorkRecords { get; set; } public DbSet<AppSettings> AppSettings { get; set; } public DbSet<Department> Departments { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { //Файл базы рядом с exe string dbPath = Path.Combine(AppContext.BaseDirectory, "WorkerTime.db"); optionsBuilder.UseSqlite($"Data Source={dbPath}"); } //Связи protected override void OnModelCreating(ModelBuilder modelBuilder) { //Уникальный табельный modelBuilder.Entity<Employee>() .HasIndex(e => e.PersonnelNumber) .IsUnique(); //Связь многие к одному modelBuilder.Entity<WorkRecord>() .HasOne(w => w.Employee) .WithMany() .HasForeignKey(w => w.EmployeeId); modelBuilder.Entity<Employee>() .HasOne(e => e.Department) .WithMany() .HasForeignKey(e => e.DepartmentId); } } }