/// <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); }
/// <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); }