Initial
This commit is contained in:
		
							
								
								
									
										74
									
								
								Repositories/FwDbContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								Repositories/FwDbContext.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using Datamodels.Lookups; | ||||
| using Datamodels.DatabaseModels; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.Configuration; | ||||
|  | ||||
| namespace Repositories | ||||
| { | ||||
|     public class FwDbContext: DbContext | ||||
|     { | ||||
|         public string _connectionString { get; set; } = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example"; | ||||
|  | ||||
|         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||||
|         { | ||||
|  | ||||
|             optionsBuilder.UseMySql(_connectionString); | ||||
|         } | ||||
|  | ||||
|         public DbSet<LookupCategory> LookupCategories { get; set; } | ||||
|         public DbSet<LookupValue> LookupValues { get; set; } | ||||
|         public DbSet<Address> Address { get; set; } | ||||
|         public DbSet<Person> Person { get; set; } | ||||
|         public DbSet<Communication> Communication { get; set; } | ||||
|  | ||||
|         protected override void OnModelCreating(ModelBuilder modelBuilder) | ||||
|         { | ||||
|  | ||||
|             modelBuilder.Entity<LookupValue>() | ||||
|                 .HasKey(x => x.Id); | ||||
|  | ||||
|             modelBuilder.Entity<LookupValue>() | ||||
|                 .Property(x => x.Id).ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<LookupCategory>() | ||||
|                 .HasKey(x => x.Id); | ||||
|  | ||||
|             modelBuilder.Entity<LookupCategory>() | ||||
|                 .Property(x => x.Id).ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<LookupCategory>() | ||||
|                 .HasMany(x => x.LookupValues) | ||||
|                 .WithOne(y => y.LookupCategory); | ||||
|  | ||||
|             modelBuilder.Entity<Person>() | ||||
|                 .Property(x => x.Id).ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<Person>() | ||||
|                 .HasKey(x => x.Id); | ||||
|  | ||||
|             modelBuilder.Entity<Person>() | ||||
|                 .HasMany(x => x.Communications) | ||||
|                 .WithOne(y => y.Person); | ||||
|  | ||||
|             modelBuilder.Entity<Person>() | ||||
|                 .HasMany(x => x.Addresses) | ||||
|                 .WithOne(y => y.Person); | ||||
|  | ||||
|             modelBuilder.Entity<Address>() | ||||
|                 .Property(x => x.Id).ValueGeneratedOnAdd(); | ||||
|              | ||||
|             modelBuilder.Entity<Address>() | ||||
|                 .HasKey(x => x.Id); | ||||
|  | ||||
|             modelBuilder.Entity<Communication>() | ||||
|                 .Property(x => x.Id).ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<Communication>() | ||||
|                 .HasKey(x => x.Id); | ||||
|              | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user