コード例 #1
0
        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"));
        }
コード例 #2
0
        /// <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);
        }