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.

DataBaseContext.cs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Karsha_Site.Application.Interfaces.Contexts;
  2. using Karsha_Site.Domain.Entinies.Products;
  3. using Karsha_Site.Domain.Entinies.Customers;
  4. using Microsoft.EntityFrameworkCore;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Karsha_Site.Domain.Entities.Products;
  11. using Karsha_Site.Domain.Entities.About;
  12. using System.ComponentModel;
  13. namespace Karsha_Site.Persistance.Contexts
  14. {
  15. public class DataBaseContext:DbContext, IDataBaseContext
  16. {
  17. public DataBaseContext(DbContextOptions options) : base(options)
  18. {
  19. }
  20. public DbSet<Customer> Customers { get; set; }
  21. public DbSet<Category> Categories { get; set; }
  22. public DbSet<Product> Products { get; set; }
  23. public DbSet<ProductImages> ProductImages { get; set; }
  24. public DbSet<ProductFeatures> ProductFeatures { get; set; }
  25. public DbSet<AboutUs> Abouts { get; set; }
  26. public DbSet<AboutAddress> AboutAddress { get; set; }
  27. public DbSet<AboutTels> AboutTels { get; set; }
  28. protected override void OnModelCreating(ModelBuilder modelBuilder)
  29. {
  30. //افزودن مقادیر پیشفرض به جدول Roles
  31. //modelBuilder.Entity<Role>().HasData(new Role { Id = 1, Name = nameof(UserRoles.Admin) });
  32. //modelBuilder.Entity<Role>().HasData(new Role { Id = 2, Name = nameof(UserRoles.Operator) });
  33. //modelBuilder.Entity<Role>().HasData(new Role { Id = 3, Name = nameof(UserRoles.Customer) });
  34. //// اعمال ایندکس بر روی فیلد ایمیل
  35. //// اعمال عدم تکراری بودن ایمیل
  36. //modelBuilder.Entity<User>().HasIndex(u => u.Email).IsUnique();
  37. //--
  38. modelBuilder.Entity<Customer>().HasQueryFilter(p => !p.IsRemoved);
  39. modelBuilder.Entity<Category>().HasQueryFilter(p => !p.IsRemoved);
  40. modelBuilder.Entity<AboutUs>().HasQueryFilter(p => !p.IsRemoved);
  41. modelBuilder.Entity<AboutAddress>().HasQueryFilter(p => !p.IsRemoved);
  42. modelBuilder.Entity<AboutTels>().HasQueryFilter(p => !p.IsRemoved);
  43. modelBuilder.Entity<Product>().HasQueryFilter(p => !p.IsRemoved);
  44. modelBuilder.Entity<ProductFeatures>().HasQueryFilter(p => !p.IsRemoved);
  45. modelBuilder.Entity<ProductImages>().HasQueryFilter(p => !p.IsRemoved);
  46. }
  47. }
  48. }