Diplom_O/DataBase/ConnectDB.cs
2021-07-25 09:43:21 +05:00

96 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace Diplom_O.DataBase
{
public class MainDB : DbContext
{
public DbSet<Shtat> Shtat { get; set; }
public DbSet<Rabotnik> Rabotniky { get; set; }
public DbSet<Chel> Chely { get; set; }
public DbSet<ChelToChel> ChelToChely { get; set; }
public MainDB()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Diplom_O.db;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder) { }
}
public class Rabotnik
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Chel")]
public int ChelId { get; set; }
public Chel Chel { get; set; }
[ForeignKey("Shtat")]
public int ShtatId { get; set; }
public Shtat Shtat { get; set; }
public string KodSotr { get; set; }
public string Kategoriya { get; set; }
public bool Pensiya { get; set; }
public DateTime Start { get; set; }
public DateTime? End { get; set; }
}
public class Shtat
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Doljnost { get; set; }
public int Size { get; set; }
public bool Active { get; set; }
}
public class Chel
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string FName { get; set; }
public string SName { get; set; }
public string TName { get; set; }
public bool Male { get; set; }
public DateTime Birthday { get; set; }
public string Address { get; set; }
public string INN { get; set; }
public string SNILS { get; set; }
public string Pasport { get; set; }
public List<Rabotnik> Rabota { get; set; }
}
public class ChelToChel
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Chel1")]
public int Chel1Id { get; set; }
public Chel Chel1 { get; set; }
[ForeignKey("Chel2")]
public int Chel2Id { get; set; }
public Chel Chel2 { get; set; }
public int Lvl { get; set; }
}
}