using CAPI.Custom.Entities; using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.SqlClient; using System.Linq; using System.Data.Entity.Design.PluralizationServices; using System.Globalization; using System.Data.Entity.Validation; using CAPI.Custom.Security; using System.Threading; using CAPI.Custom.Entities.publ.PurchaseOrders; using System.Data.Entity.Infrastructure; namespace CAPI.Custom.Data { public partial class QuotesContext : DbContext { protected bool EnableSurfaceDataSaving = true; protected readonly string ConnectionStringName; public ICustomPrincipal User => (Thread.CurrentPrincipal as ICustomPrincipal) ?? new CustomPrincipal(""); public static QuotesContext Create() { return new QuotesContext(); } #region Constructors public QuotesContext() : this("name=Quotes") { } public QuotesContext(string nameOrConnectionString) : base(nameOrConnectionString) { // prevents EF from attempting to create // the database or generate migrations. Database.SetInitializer(null); //Database.Log = s => System.IO.File.AppendAllLines(@"c:\temp\ef.log", new string[] { "", s }); Database.CommandTimeout = 180; if (nameOrConnectionString.StartsWith("name=", StringComparison.OrdinalIgnoreCase)) { ConnectionStringName = nameOrConnectionString.Replace("name=", ""); } RegisterEvents(); } protected override void Dispose(bool disposing) { UnregisterEvents(); base.Dispose(disposing); } #endregion protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.AddFromAssembly(GetType().Assembly); modelBuilder.Entity().HasMany(u => u.PurchaseOrderStatuses) .WithMany() .Map(ru => { ru.MapLeftKey("DocumentTypeId"); ru.MapRightKey("PurchaseOrderStatusId"); ru.ToTable("publ_PurchaseOrderDocumentTypeStatus"); }); modelBuilder.Entity().HasMany(u => u.DocumentStatuses) .WithMany() .Map(ru => { ru.MapLeftKey("DocumentTypeId"); ru.MapRightKey("DocumentStatusId"); ru.ToTable("publ_PurchaseOrderDocumentTypeDocumentStatus"); }); modelBuilder .Entity() .Property(p => p.RowVersion) .IsConcurrencyToken(); base.OnModelCreating(modelBuilder); } #region Mapped Tables #region Views public DbSet Users { get; set; } public DbSet vQuotes { get; set; } public DbSet vQuoteGridItems { get; set; } //public DbSet vQuoteItems { get; set; } #endregion public DbSet Surfaces { get; set; } public DbSet SurfaceFields { get; set; } public DbSet SurfaceFieldDatas { get; set; } public DbSet SurfaceFieldTypes { get; set; } public DbSet SurfaceItems { get; set; } public DbSet Customers { get; set; } public DbSet Contacts { get; set; } public DbSet SurfaceLookupCategories { get; set; } public DbSet SurfaceLookups { get; set; } public DbSet Quotes { get; set; } public DbSet QuoteItems { get; set; } //public DbSet QuoteItemsPriceChecks { get; set; } public DbSet QuoteEnquiryItems { get; set; } public DbSet QuoteRequestItems { get; set; } public DbSet QuoteBuyoutSuppliers { get; set; } public DbSet QuoteBuyoutItems { get; set; } public DbSet QuoteItemsFinal { get; set; } public DbSet PartsAlternates { get; set; } public DbSet PartsMasters { get; set; } public DbSet Sales { get; set; } public DbSet SalesExtraNotes { get; set; } public DbSet Suppliers { get; set; } public DbSet ExchangeRates { get; set; } public DbSet Freights { get; set; } public DbSet Brands { get; set; } public DbSet Conditions { get; set; } public DbSet SupplierPricelistParts { get; set; } public DbSet Setups { get; set; } public DbSet Currencies { get; set; } public DbSet InventoryItems { get; set; } public DbSet