using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace eCompanies { public partial class CompaniesDBContext : DbContext { public CompaniesDBContext() { } public CompaniesDBContext(DbContextOptions options) : base(options) { } public virtual DbSet Company { get; set; } public virtual DbSet 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(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(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"); }); } } }