// ====================================== // Author: Ebenezer Monney // Email: info@ebenmonney.com // Copyright (c) 2017 www.ebenmonney.com // // ==> Gun4Hire: contact@ebenmonney.com // ====================================== using DAL.Models; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using OpenIddict; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DAL { public class ApplicationDbContext : IdentityDbContext { public DbSet Customers { get; set; } public DbSet ProductCategories { get; set; } public DbSet Products { get; set; } public DbSet Orders { get; set; } public DbSet OrderDetails { get; set; } public ApplicationDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity().Property(c => c.Name).IsRequired().HasMaxLength(100); builder.Entity().HasIndex(c => c.Name); builder.Entity().Property(c => c.Email).HasMaxLength(100); builder.Entity().Property(c => c.PhoneNumber).IsUnicode(false).HasMaxLength(30); builder.Entity().Property(c => c.City).HasMaxLength(50); builder.Entity().ToTable($"App{nameof(this.Customers)}"); builder.Entity().Property(p => p.Name).IsRequired().HasMaxLength(100); builder.Entity().Property(p => p.Description).HasMaxLength(500); builder.Entity().ToTable($"App{nameof(this.ProductCategories)}"); builder.Entity().Property(p => p.Name).IsRequired().HasMaxLength(100); builder.Entity().HasIndex(p => p.Name); builder.Entity().Property(p => p.Description).HasMaxLength(500); builder.Entity().Property(p => p.Icon).IsUnicode(false).HasMaxLength(256); builder.Entity().HasOne(p => p.Parent).WithMany(p => p.Children).OnDelete(DeleteBehavior.Restrict); builder.Entity().ToTable($"App{nameof(this.Products)}"); builder.Entity().Property(o => o.Comments).HasMaxLength(500); builder.Entity().ToTable($"App{nameof(this.Orders)}"); builder.Entity().ToTable($"App{nameof(this.OrderDetails)}"); } } }