148 lines
5.5 KiB
C#
148 lines
5.5 KiB
C#
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<PastoralDomain> PastoralDomains { get; set; }
|
|
// //public DbSet<FamilyMember> FamilyMembers { get; set; }
|
|
// //public DbSet<Career> Careers { get; set; }
|
|
// public DbSet<NewVisitor> NewVisitors { get; set; }
|
|
// //public DbSet<Religion> Religions { get; set; }
|
|
|
|
|
|
// protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
|
// {
|
|
// modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
|
|
// }
|
|
//}
|
|
|
|
|
|
public class ChurchNetContext : DbContext
|
|
{
|
|
private static bool _created = true;
|
|
private readonly string connectionString;
|
|
|
|
|
|
public ChurchNetContext(DbContextOptions<ChurchNetContext> 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<PastoralDomain> PastoralDomains { get; set; }
|
|
//public DbSet<FamilyMember> FamilyMembers { get; set; }
|
|
//public DbSet<Career> Careers { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
//modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
|
|
modelBuilder.Entity<CellGroupRoutineEventAttendee>()
|
|
.HasKey(tt => new { tt.EventId, tt.Id });
|
|
|
|
modelBuilder.Entity<CellGroupRoutineEventPrayer>()
|
|
.HasKey(tt => new { tt.EventId, tt.MemberId });
|
|
|
|
modelBuilder.Entity<FamilyMemberOAuth>()
|
|
.HasKey(tt => new { tt.FamilyMemberId, tt.OAuthType });
|
|
|
|
modelBuilder.Entity<PastoralDomainMembers>()
|
|
.HasKey(tt => new { tt.PastoralDomainId, tt.FamilyMemberId });
|
|
|
|
|
|
|
|
modelBuilder.Entity<PastoralDomainAutoReplys>()
|
|
.HasKey(tt => new { tt.PastoralDomainCommunityAppId, tt.AutoReplyItemId });
|
|
modelBuilder.Entity<PastoralDomainAutoReplys>()
|
|
.HasOne(tt => tt.PastoralDomain)
|
|
.WithMany(t => t.AutoReplyItemRelations)
|
|
.HasForeignKey(tt => tt.PastoralDomainCommunityAppId)
|
|
.HasPrincipalKey(tt => tt.CommunityAppId);
|
|
|
|
//modelBuilder.Entity<PastoralDomainMembers>()
|
|
// .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<Church.Net.Entity.FamilyMember> FamilyMembers { get; set; }
|
|
|
|
#region DbSet
|
|
|
|
public DbSet<NewVisitor> NewVisitors { get; set; }
|
|
public DbSet<Religion> Religions { get; set; }
|
|
public DbSet<FamilyMemberOAuth> FamilyMemberOAuths { get; set; }
|
|
public DbSet<FamilyMember> FamilyMembers { get; set; }
|
|
public DbSet<PastoralDomainMembers> PastoralDomainMembers { get; set; }
|
|
public DbSet<Career> Careers { get; set; }
|
|
public DbSet<PastoralDomain> PastoralDomains { get; set; }
|
|
public DbSet<WhoIsSpy> WhoIsSpy { get; set; }
|
|
public DbSet<Vocabulary> Vocabulary { get; set; }
|
|
public DbSet<HappinessGroup> HappinessGroups { get; set; }
|
|
public DbSet<HappinessBEST> HappinessBESTs { get; set; }
|
|
public DbSet<HappinessWeek> HappinessWeeks { get; set; }
|
|
public DbSet<CellGroupRoutineEvent> CellGroupRoutineEvents { get; set; }
|
|
public DbSet<CellGroupRoutineEventAttendee> CellGroupRoutineEventAttendees { get; set; }
|
|
public DbSet<CellGroupRoutineEventPrayer> CellGroupRoutineEventPrayers { get; set; }
|
|
public DbSet<LogInfo> LogInfos { get; set; }
|
|
public DbSet<AutoReplyItem> AutoReplyItems { get; set; }
|
|
public DbSet<AddressInfo> AddressInfos { get; set; }
|
|
public DbSet<LineMessageClient> LineMessageClients { get; set; }
|
|
public DbSet<LineMessagingAccount> LineMessagingAccounts { get; set; }
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
}
|