RHDWContext.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SQLite.CodeFirst;
  8. using System.Data.Entity.ModelConfiguration.Conventions;
  9. using System.Data.Entity.Infrastructure.Interception;
  10. using XdCxRhDW.Repostory.Model;
  11. namespace XdCxRhDW.Repostory.EFContext
  12. {
  13. public class RHDWContext: DbContext
  14. {
  15. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  16. {
  17. //modelBuilder.Entity<TaskInfo>().Map(m =>
  18. //{
  19. // m.MapInheritedProperties();
  20. // m.ToTable("TaskInfo");
  21. //});
  22. this.Database.Log = msg =>
  23. {
  24. };
  25. modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
  26. modelBuilder.Configurations.AddFromAssembly(typeof(RHDWContext).Assembly);
  27. var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<RHDWContext>(modelBuilder);
  28. Database.SetInitializer(sqliteConnectionInitializer);
  29. DbInterception.Add(new SqliteInterceptor());//拦截器
  30. base.OnModelCreating(modelBuilder);
  31. }
  32. public RHDWContext() : base("DbCon") { } //配置使用的连接名
  33. public DbSet<XlInfo> XlInfos { set; get; }
  34. public DbSet<TaskInfo> TaskInfos { set; get; }
  35. public DbSet<TxInfo> TxInfos { get; set; }
  36. public DbSet<SatInfo> SatInfos { get; set; }
  37. public DbSet<TargetInfo> TargetInfos { get; set; }
  38. public DbSet<StationRes> StationRes { get; set; }
  39. public DbSet<CxRes> CxRes { get; set; }
  40. public DbSet<CgRes> CgRes { get; set; }
  41. public DbSet<PosRes> PosRes { get; set; }
  42. public DbSet<SysSetings> SysSetings { get; set; }
  43. }
  44. }