/// <summary>
        /// Sets context mappings source to static entity works context.
        /// </summary>
        private static void SetContextMappingsSource(IConfigurationSection section)
        {
            // Get connection strings section.
            var contextMappingsSection = section.GetSection("ContextMappings") ??
                                         throw new EntityWorksException("EntityWorks section does not have ContextMappings section. " +
                                                                        "Please refer to documentation.");

            // Get context mappings.
            var contextMappings = contextMappingsSection
                                  .GetChildren()
                                  .ToDictionary(x => x.Key, x => x.Value);

            // Set connection string source.
            EntityWorksContext.SetContextMappingsSource(contextMappings);
        }
        /// <summary>
        /// Sets connection strings source to static entity works context.
        /// </summary>
        private static void SetConnectionStringSource(IConfiguration configuration)
        {
            // Get connection strings section.
            var connectionStringsSection = configuration.GetSection("ConnectionStrings") ??
                                           throw new EntityWorksException("Configuration does not have ConnectionStrings section. " +
                                                                          "Please refer to documentation.");

            // Get connection contexts.
            var connectionContexts = connectionStringsSection
                                     .GetChildren()
                                     .ToDictionary(x => x.Key, x => new ConnectionContext(
                                                       connectionString: x.GetSection("ConnectionString").Value,
                                                       providerAssembly: x.GetSection("ProviderAssembly").Value,
                                                       providerFactory: x.GetSection("ProviderFactory").Value
                                                       ));

            // Set connection string source.
            EntityWorksContext.SetConnectionStringSource(connectionContexts);
        }
        public async Task <IActionResult> FeaturesTest1()
        {
            // Json result.
            string jsonResult;

            var ewContext = EntityWorksContext.GetEntityWorksContext();

            // Use northwind tunnel.
            using (var context = new NorthwindContext())
            {
                // Get all orders.
                var orders = await Northwind.Dbo.Orders.GetByAnyAsync();

                // Use adventureworks tunnel.
                using (var context2 = new AdventureWorksContext())
                {
                    // Get all orders.
                    var addresses = await AdventureWorks.Person.Address.GetByAnyAsync();

                    // Get all addresses.
                    var address = await AdventureWorks.Person.Address.GetByPrimaryKeyAsync(1);
                }
            }

            // Use adventureworks tunnel.
            using (var context = new AdventureWorksContext())
            {
                // Get all orders.
                var addresses = await AdventureWorks.Person.Address.GetByAnyAsync();

                // Get all addresses.
                var address = await AdventureWorks.Person.Address.GetByPrimaryKeyAsync(1);

                // Convert data to json.
                jsonResult = JsonSerializer.Serialize(addresses, null);
            }

            // Display json data.
            return(Content(jsonResult, "application/json"));
        }
        /// <summary>
        /// Initializes entity works runtime.
        /// </summary>
        public void InitializeEntityWorks()
        {
            // Create connection context.
            var connectionContext = new ConnectionContext(
                "Data Source=DESKTOP-JLE7CPB;Initial Catalog=AdventureWorks;Integrated Security=True",
                "Microsoft.Data.SqlClient",
                "Microsoft.Data.SqlClient.SqlClientFactory");

            // Create connection context dictionary.
            var ccDictionary = new Dictionary <string, ConnectionContext>();

            ccDictionary.Add("AdventureWorks", connectionContext);

            // Create connection mappings dictionary.
            var mcDictionary = new Dictionary <string, string>();

            mcDictionary.Add("GuestContext", "AdventureWorks");
            mcDictionary.Add("UserContext", "AdventureWorks");
            mcDictionary.Add("RootContext", "AdventureWorks");

            // Set entity works connection context source.
            EntityWorksContext.SetConnectionStringSource(ccDictionary);

            // Set entity works connection mappings source.
            EntityWorksContext.SetContextMappingsSource(mcDictionary);

            // Get entity works context instance.
            var entityWorksContext = EntityWorksContext.GetEntityWorksContext();

            // Initialize entity works context.
            entityWorksContext
            .RegisterGuestContext()
            .RegisterRootContext()
            .RegisterUserContext()
            .SetLanguageCode("HR")
            .SetDebugMode(true);
        }