You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.9 KiB
66 lines
1.9 KiB
using System;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
|
|
namespace eCompanies
|
|
{
|
|
public partial class CompaniesDBContext : DbContext
|
|
{
|
|
public CompaniesDBContext()
|
|
{
|
|
}
|
|
|
|
public CompaniesDBContext(DbContextOptions<CompaniesDBContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public virtual DbSet<Company> Company { get; set; }
|
|
public virtual DbSet<Users> Users { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=CompaniesDB;Trusted_Connection=True;");
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Company>(entity =>
|
|
{
|
|
entity.HasKey(e => e.CompanyId);
|
|
|
|
entity.Property(e => e.ContractStatus)
|
|
.IsRequired();
|
|
|
|
entity.Property(e => e.Name).IsRequired();
|
|
|
|
entity.Ignore("contract");
|
|
|
|
entity.Ignore("dataGridRowStatus");
|
|
});
|
|
|
|
modelBuilder.Entity<Users>(entity =>
|
|
{
|
|
entity.HasKey(e => e.UserId);
|
|
|
|
entity.Property(e => e.CompanyId).HasColumnName("CompanyID");
|
|
|
|
entity.Property(e => e.Login).IsRequired();
|
|
|
|
entity.Property(e => e.Name).IsRequired();
|
|
|
|
entity.Property(e => e.Password).IsRequired();
|
|
|
|
entity.HasOne(d => d.Company)
|
|
.WithMany(p => p.Users)
|
|
.HasForeignKey(d => d.CompanyId)
|
|
.HasConstraintName("FK_Users_Company");
|
|
|
|
entity.Ignore("dataGridRowStatus");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|