| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // ======================================
- // 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<ApplicationUser, ApplicationRole, string>
- {
- public DbSet<Customer> Customers { get; set; }
- public DbSet<ProductCategory> ProductCategories { get; set; }
- public DbSet<Product> Products { get; set; }
- public DbSet<Order> Orders { get; set; }
- public DbSet<OrderDetail> OrderDetails { get; set; }
- public ApplicationDbContext(DbContextOptions options) : base(options)
- { }
- protected override void OnModelCreating(ModelBuilder builder)
- {
- base.OnModelCreating(builder);
- builder.Entity<Customer>().Property(c => c.Name).IsRequired().HasMaxLength(100);
- builder.Entity<Customer>().HasIndex(c => c.Name);
- builder.Entity<Customer>().Property(c => c.Email).HasMaxLength(100);
- builder.Entity<Customer>().Property(c => c.PhoneNumber).IsUnicode(false).HasMaxLength(30);
- builder.Entity<Customer>().Property(c => c.City).HasMaxLength(50);
- builder.Entity<Customer>().ToTable($"App{nameof(this.Customers)}");
- builder.Entity<ProductCategory>().Property(p => p.Name).IsRequired().HasMaxLength(100);
- builder.Entity<ProductCategory>().Property(p => p.Description).HasMaxLength(500);
- builder.Entity<ProductCategory>().ToTable($"App{nameof(this.ProductCategories)}");
- builder.Entity<Product>().Property(p => p.Name).IsRequired().HasMaxLength(100);
- builder.Entity<Product>().HasIndex(p => p.Name);
- builder.Entity<Product>().Property(p => p.Description).HasMaxLength(500);
- builder.Entity<Product>().Property(p => p.Icon).IsUnicode(false).HasMaxLength(256);
- builder.Entity<Product>().HasOne(p => p.Parent).WithMany(p => p.Children).OnDelete(DeleteBehavior.Restrict);
- builder.Entity<Product>().ToTable($"App{nameof(this.Products)}");
- builder.Entity<Order>().Property(o => o.Comments).HasMaxLength(500);
- builder.Entity<Order>().ToTable($"App{nameof(this.Orders)}");
- builder.Entity<OrderDetail>().ToTable($"App{nameof(this.OrderDetails)}");
- }
- }
- }
|