1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
---|
2 | using Microsoft.EntityFrameworkCore;
|
---|
3 | using PostgreSqlDotnetCore.Models;
|
---|
4 | using System.Xml;
|
---|
5 |
|
---|
6 | namespace PostgreSqlDotnetCore.Data
|
---|
7 | {
|
---|
8 | public class ApplicationDbContext : IdentityDbContext
|
---|
9 | {
|
---|
10 | public ApplicationDbContext() {}
|
---|
11 | public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
---|
12 | : base(options)
|
---|
13 | {
|
---|
14 | }
|
---|
15 |
|
---|
16 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
---|
17 | {
|
---|
18 | if (!optionsBuilder.IsConfigured)
|
---|
19 | {
|
---|
20 | IConfigurationRoot configuration = new ConfigurationBuilder()
|
---|
21 | .SetBasePath(Directory.GetCurrentDirectory())
|
---|
22 | .AddJsonFile("appsettings.json")
|
---|
23 | .Build();
|
---|
24 | var connectionString = configuration.GetConnectionString("DefaultConnection");
|
---|
25 | optionsBuilder.UseNpgsql(connectionString);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected override void OnModelCreating(ModelBuilder modelBuilder)
|
---|
30 | {
|
---|
31 | modelBuilder.HasDefaultSchema("project");
|
---|
32 | modelBuilder.Entity<UsersClass>().ToTable("users", t => t.ExcludeFromMigrations());
|
---|
33 | modelBuilder.Entity<VetCenter>().ToTable("vet_centers", t => t.ExcludeFromMigrations());
|
---|
34 | modelBuilder.Entity<BlogPostConsultation>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
35 | modelBuilder.Entity<RolesClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
36 | modelBuilder.Entity<CitiesClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
37 | modelBuilder.Entity<ProductsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
38 | modelBuilder.Entity<DiagnosticsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
39 | modelBuilder.Entity<OrdersClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
40 | modelBuilder.Entity<Pet_StatusClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
41 | modelBuilder.Entity<BreedsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
42 | modelBuilder.Entity<JobsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
43 | modelBuilder.Entity<ManufacturersClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
44 | modelBuilder.Entity<Pet_CaresClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
45 | modelBuilder.Entity<PetsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
46 | modelBuilder.Entity<ReportsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
47 | modelBuilder.Entity<TherapyClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
48 | modelBuilder.Entity<Type_Of_PetsClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
49 | modelBuilder.Entity<MedecinesClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
50 | modelBuilder.Entity<Pet_GaleryClass>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
51 | modelBuilder.Entity<BlogPostAnswers>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
52 |
|
---|
53 | modelBuilder.Entity<PetDetailsProcedure>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
54 | //modelBuilder.Entity<PetCareAllData>().Metadata.SetIsTableExcludedFromMigrations(true);
|
---|
55 |
|
---|
56 | // додадени следните два реда на 28.08
|
---|
57 | // modelBuilder.Entity<VetCenterWithCity>().HasNoKey(); // Дефинирајте дека VIEW-от нема примарен клуч
|
---|
58 | // modelBuilder.Entity<VetCenterWithCity>().ToView("vet_centers_with_city"); // Поставете го името на VIEW-от
|
---|
59 | modelBuilder.Entity<VetCenterWithCity>().HasNoKey().ToView("vet_centers_with_city");
|
---|
60 | base.OnModelCreating(modelBuilder);
|
---|
61 |
|
---|
62 |
|
---|
63 | modelBuilder.Entity<BlogUsers>().HasNoKey().ToView("view_userss_consultationss");
|
---|
64 | base.OnModelCreating(modelBuilder);
|
---|
65 | // Configure the relationship between VetCenter and CitiesClass
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 | // ... model definition ...
|
---|
70 | }
|
---|
71 |
|
---|
72 | public virtual DbSet<UsersClass> CustomerObj { get; set; }
|
---|
73 | public virtual DbSet<VetCenter> VetCentersObj { get; set; }
|
---|
74 |
|
---|
75 | // додадено на 28.08
|
---|
76 | public virtual DbSet<VetCenterWithCity> VetCentersWithCity { get; set; }
|
---|
77 |
|
---|
78 | public virtual DbSet<BlogUsers> BlogUsers { get; set; }
|
---|
79 | public virtual DbSet<BlogPostConsultation> BlogPostControllerObj { get; set; }
|
---|
80 | public virtual DbSet<RolesClass> RoleControllerObj { get; set; }
|
---|
81 | public virtual DbSet<CitiesClass> CitiesObj { get; set; }
|
---|
82 | public virtual DbSet<ProductsClass> ProductObj { get; set; }
|
---|
83 | public virtual DbSet<DiagnosticsClass> DiagObj { get; set; }
|
---|
84 | public virtual DbSet<BlogPostAnswers> BlogPostAnswersObj { get; set; }
|
---|
85 | public virtual DbSet<OrdersClass> OrderObj { get; set; }
|
---|
86 | public virtual DbSet<Pet_StatusClass> PetStatusObj { get; set; }
|
---|
87 | public virtual DbSet<BreedsClass> BreedsObj { get; set; }
|
---|
88 | public virtual DbSet<JobsClass> JobsObj { get; set; }
|
---|
89 | public virtual DbSet<ManufacturersClass> ManObj { get; set; }
|
---|
90 | public virtual DbSet<MedecinesClass> MedeObj { get; set; }
|
---|
91 | public virtual DbSet<Pet_CaresClass> PetCaresObj { get; set; }
|
---|
92 | //public virtual DbSet<PetCareAllData> PetCaresWithAllDataObj { get; set; }
|
---|
93 | public virtual DbSet<PetsClass> PetsObj { get; set; }
|
---|
94 | public virtual DbSet<ReportsClass> repObj { get; set; }
|
---|
95 | public virtual DbSet<TherapyClass> theraObj { get; set; }
|
---|
96 | public virtual DbSet<Type_Of_PetsClass> typeofObj { get; set; }
|
---|
97 |
|
---|
98 | public virtual DbSet<PetDetailsProcedure> PetDetailsProcedureObj { get; set; }
|
---|
99 |
|
---|
100 | //public virtual DbSet<PetDetailsProcedure> AddVetCenter { get; set; }
|
---|
101 |
|
---|
102 | }
|
---|
103 | } |
---|