using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using IdeaBlade.EntityModel;
using System.Data.Entity.Infrastructure;

namespace iRely.Model
{
    [DataSourceKeyName("iRelyGlobalEntities")]
    public class GlobalDBContext : DbContext
    {
      public GlobalDBContext(string connection = null)
        : base(connection) {
          //Database.DefaultConnectionFactory = new SqlConnectionFactory("data source=.;initial catalog=iRelySuite;integrated security=True;multipleactiveresultsets=True;App=EntityFramework");
          Database.SetInitializer(new CreateDatabaseIfNotExists<GlobalDBContext>());
      }

      public GlobalDBContext()
        : base() {
      }

        #region Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Ignore<EntityAspect>();

            modelBuilder.Entity<tblSMSecurityMenuList>()
              .HasOptional(t => t.tblSMImageFile)
              .WithRequired(t => t.tblSMSecurityMenuList);

            modelBuilder.Entity<tblSMSearchDefaultField>()
              .HasRequired(t => t.tblSMSearch)
              .WithOptional(t => t.tblSMSearchDefaultField);

            modelBuilder.Entity<tblSMSearchLockedField>()
              .HasRequired(t => t.tblSMSearch)
              .WithOptional(t => t.tblSMSearchLockedField);

            modelBuilder.Entity<tblSMSearchSorting>()
              .HasRequired(t => t.tblSMSearch)
              .WithOptional(t => t.tblSMSearchSorting);
        }
        #endregion


        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMCity entities. </summary>
        public DbSet<tblSMCity> tblSMCities {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMCompanySetup entities. </summary>
        public DbSet<tblSMCompanySetup> tblSMCompanySetups
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMCountry entities. </summary>
        public DbSet<tblSMCountry> tblSMCountries
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMCurrency entities. </summary>
        public DbSet<tblSMCurrency> tblSMCurrencies
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMCurrencyDetail entities. </summary>
        public DbSet<tblSMCurrencyDetail> tblSMCurrencyDetails
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMImageFile entities. </summary>
        public DbSet<tblSMImageFile> tblSMImageFiles
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMMenuFavorite entities. </summary>
        public DbSet<tblSMMenuFavorite> tblSMMenuFavorites
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMMenuPreference entities. </summary>
        public DbSet<tblSMMenuPreference> tblSMMenuPreferences
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMMenuRecent entities. </summary>
        public DbSet<tblSMMenuRecent> tblSMMenuRecents
        {
            get;
            set;
        }

         ///<summary>Gets the <see cref="T:DbSet"/> for tblSMMenuReport entities. </summary>
        public DbSet<tblSMMenuReport> tblSMMenuReports {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMPreferencesCompany entities. </summary>
        public DbSet<tblSMPreferencesCompany> tblSMPreferencesCompanies
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMPreferencesUser entities. </summary>
        public DbSet<tblSMPreferencesUser> tblSMPreferencesUsers
        {
            get;
            set;
        }

         ///<summary>Gets the <see cref="T:DbSet"/> for tblSMProduct entities. </summary>
        public DbSet<tblSMProduct> tblSMProducts {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearch entities. </summary>
        public DbSet<tblSMSearch> tblSMSearches
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchDefaultField entities. </summary>
        public DbSet<tblSMSearchDefaultField> tblSMSearchDefaultFields {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchDefaultFilter entities. </summary>
        public DbSet<tblSMSearchDefaultFilter> tblSMSearchDefaultFilters
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchDefaultGroup entities. </summary>
        public DbSet<tblSMSearchDefaultGroup> tblSMSearchDefaultGroups
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchDetail entities. </summary>
        public DbSet<tblSMSearchDetail> tblSMSearchDetails
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchLockedField entities. </summary>
        public DbSet<tblSMSearchLockedField> tblSMSearchLockedFields {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchMatching entities. </summary>
        public DbSet<tblSMSearchMatching> tblSMSearchMatchings
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchSavedSearch entities. </summary>
        public DbSet<tblSMSearchSavedSearch> tblSMSearchSavedSearches
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSearchSorting entities. </summary>
        public DbSet<tblSMSearchSorting> tblSMSearchSortings {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityControlList entities. </summary>
        public DbSet<tblSMSecurityControlList> tblSMSecurityControlLists
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityFormList entities. </summary>
        public DbSet<tblSMSecurityFormList> tblSMSecurityFormLists
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityMenuList entities. </summary>
        public DbSet<tblSMSecurityMenuList> tblSMSecurityMenuLists {
          get;
          set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityMenuUser entities. </summary>
        public DbSet<tblSMSecurityMenuUser> tblSMSecurityMenuUsers
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityMenuUserDetail entities. </summary>
        public DbSet<tblSMSecurityMenuUserDetail> tblSMSecurityMenuUserDetails
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityModuleList entities. </summary>
        public DbSet<tblSMSecurityModuleList> tblSMSecurityModuleLists
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPermissionGroup entities. </summary>
        public DbSet<tblSMSecurityPermissionGroup> tblSMSecurityPermissionGroups
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPermissionGroupControl entities. </summary>
        public DbSet<tblSMSecurityPermissionGroupControl> tblSMSecurityPermissionGroupControls
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPermissionGroupForm entities. </summary>
        public DbSet<tblSMSecurityPermissionGroupForm> tblSMSecurityPermissionGroupForms
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPermissionGroupMenu entities. </summary>
        public DbSet<tblSMSecurityPermissionGroupMenu> tblSMSecurityPermissionGroupMenus
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPolicy entities. </summary>
        public DbSet<tblSMSecurityPolicy> tblSMSecurityPolicies
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityPolicyGroup entities. </summary>
        public DbSet<tblSMSecurityPolicyGroup> tblSMSecurityPolicyGroups
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityReportList entities. </summary>
        public DbSet<tblSMSecurityReportList> tblSMSecurityReportLists
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUser entities. </summary>
        public DbSet<tblSMSecurityUser> tblSMSecurityUsers
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserControl entities. </summary>
        public DbSet<tblSMSecurityUserControl> tblSMSecurityUserControls
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserDefault entities. </summary>
        public DbSet<tblSMSecurityUserDefault> tblSMSecurityUserDefaults
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserForm entities. </summary>
        public DbSet<tblSMSecurityUserForm> tblSMSecurityUserForms
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserGroup entities. </summary>
        public DbSet<tblSMSecurityUserGroup> tblSMSecurityUserGroups
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserGroupControl entities. </summary>
        public DbSet<tblSMSecurityUserGroupControl> tblSMSecurityUserGroupControls
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserGroupForm entities. </summary>
        public DbSet<tblSMSecurityUserGroupForm> tblSMSecurityUserGroupForms
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserGroupMenu entities. </summary>
        public DbSet<tblSMSecurityUserGroupMenu> tblSMSecurityUserGroupMenus
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserMenu entities. </summary>
        public DbSet<tblSMSecurityUserMenu> tblSMSecurityUserMenus
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMSecurityUserRequired entities. </summary>
        public DbSet<tblSMSecurityUserRequired> tblSMSecurityUserRequireds
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMShipVia entities. </summary>
        public DbSet<tblSMShipVia> tblSMShipVias
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMState entities. </summary>
        public DbSet<tblSMState> tblSMStates
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMTerm entities. </summary>
        public DbSet<tblSMTerm> tblSMTerms
        {
            get;
            set;
        }

        /// <summary>Gets the <see cref="T:DbSet"/> for tblSMZipCode entities. </summary>
        public DbSet<tblSMZipCode> tblSMZipCodes
        {
            get;
            set;
        }
    }
}
