using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Church.Net.Entity; using Church.Net.Entity.Messenger; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace Church.Net.DAL.EF { //public class ChurchNetContext:DbContext //{ // public ChurchNetContext():base("entityFramework") // { // } // public ChurchNetContext(string connString):base(connString) // { // } // //public DbSet PastoralDomains { get; set; } // //public DbSet FamilyMembers { get; set; } // //public DbSet Careers { get; set; } // public DbSet NewVisitors { get; set; } // //public DbSet Religions { get; set; } // protected override void OnModelCreating(DbModelBuilder modelBuilder) // { // modelBuilder.Conventions.Remove(); // } //} public class ChurchNetContext : DbContext { private static bool _created = true; private readonly string connectionString; public ChurchNetContext(DbContextOptions options) : base(options) { } //public ChurchNetContext() //{ // var folder = Environment.SpecialFolder.LocalApplicationData; // var path = Environment.GetFolderPath(folder); // DbPath = System.IO.Path.Join(path, "ChurchNet.db"); // DbPath = @"C:\WebSites\ChurchNetAPI\App_Data\ChurchNet.db"; // if (!_created) // { // _created = true; // Database.EnsureDeleted(); // Database.EnsureCreated(); // } //} public ChurchNetContext(string connectionString) { this.connectionString = connectionString; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!string.IsNullOrWhiteSpace(connectionString)) { optionsBuilder.UseNpgsql(connectionString); } } //public DbSet PastoralDomains { get; set; } //public DbSet FamilyMembers { get; set; } //public DbSet Careers { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { //modelBuilder.Conventions.Remove(); modelBuilder.Entity() .HasKey(tt => new { tt.EventId, tt.Id }); modelBuilder.Entity() .HasKey(tt => new { tt.EventId, tt.MemberId }); modelBuilder.Entity() .HasKey(tt => new { tt.FamilyMemberId, tt.OAuthType }); modelBuilder.Entity() .HasKey(tt => new { tt.PastoralDomainId, tt.FamilyMemberId }); modelBuilder.Entity() .HasKey(tt => new { tt.PastoralDomainCommunityAppId, tt.AutoReplyItemId }); modelBuilder.Entity() .HasOne(tt => tt.PastoralDomain) .WithMany(t => t.AutoReplyItemRelations) .HasForeignKey(tt => tt.PastoralDomainCommunityAppId) .HasPrincipalKey(tt => tt.CommunityAppId); //modelBuilder.Entity() // .HasOne(t => t.PastoralDomain) // .WithMany(tt => tt.FamilyMember) // .HasForeignKey(f => f.ParentId); } public string DbPath { get; } //protected override void OnConfiguring(DbContextOptionsBuilder options) // => options.UseSqlite($"Data Source={DbPath}"); //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) // => optionsBuilder.UseNpgsql("Host=my_host;Database=my_db;Username=my_user;Password=my_pw"); //public System.Data.Entity.DbSet FamilyMembers { get; set; } #region DbSet public DbSet NewVisitors { get; set; } public DbSet Religions { get; set; } public DbSet FamilyMemberOAuths { get; set; } public DbSet FamilyMembers { get; set; } public DbSet PastoralDomainMembers { get; set; } public DbSet Careers { get; set; } public DbSet PastoralDomains { get; set; } public DbSet WhoIsSpy { get; set; } public DbSet Vocabulary { get; set; } public DbSet HappinessGroups { get; set; } public DbSet HappinessBESTs { get; set; } public DbSet HappinessWeeks { get; set; } public DbSet CellGroupRoutineEvents { get; set; } public DbSet CellGroupRoutineEventAttendees { get; set; } public DbSet CellGroupRoutineEventPrayers { get; set; } public DbSet LogInfos { get; set; } public DbSet AutoReplyItems { get; set; } public DbSet AddressInfos { get; set; } public DbSet LineMessageClients { get; set; } public DbSet LineMessagingAccounts { get; set; } #endregion } }