Nevar pievienot vairāk kā 25 tēmas
Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
|
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Linq;
- using System.Reflection;
- using HealthMonitor.Core.Dal;
- using HealthMonitor.Core.Map;
-
- namespace HealthMonitor.Core.Context
- {
- public class GpsCardContext : DbContext, IWithDataSchema
- {
- public string DataSchema { get; }
-
- public GpsCardContext(DbContextOptions<GpsCardContext> options)
- : base(options)
- {
- DataSchema = "gps_card";
- }
-
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- base.OnConfiguring(optionsBuilder);
- }
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.HasDefaultSchema(DataSchema);
-
- var typesToRegister = Assembly.GetExecutingAssembly().GetTypes()
- .Where(type => !string.IsNullOrEmpty(type.Namespace) && type.Namespace.StartsWith("HealthMonitor.Core.Map.GpsCard"))
- .Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(GenericEntityTypeConfiguration<>));
-
- foreach (var t in typesToRegister)
- {
- dynamic configurationInstance = Activator.CreateInstance(t)!;
- modelBuilder.ApplyConfiguration(configurationInstance);
- }
-
- base.OnModelCreating(modelBuilder);
- }
- }
- }
|