Example E4896
Visible to All Users

How to connect different data models to several databases within a single application with Entity Framework Core

This example demonstrates how to create custom XAF modules with custom business objects and logic that work with separate databases. These modules do not depend on each other and thus can be reused in other applications independently.

This EFCore example solution is based on the following tutorial: How to: Use Multiple Data Models Connected to Different Databases in Entity Framework Core.

Note that business classes linked to different ObjectSpaceProviders are considered to be isolated from each other and thus cannot have direct links between them, e.g., an association between two classes. Consider using the How to prevent altering the legacy database schema when creating an XAF application or alternative solutions if you need interlinks between classes from different data stores.

Note
For information on how to achieve the same functionality with XPO on .NET 6+ and .NET Framework, see the Readme.md files in the respective solution folders:

.NET 6+

.NET Framework

Files to Review

Modules:

Blazor application:

WinForms application:

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/ClassLibrary1/ClassLibrary1DbContext.cs
C#
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using DevExpress.ExpressApp.Design; using DevExpress.ExpressApp.EFCore.DesignTime; namespace ClassLibrary1; // This code allows our Model Editor to get relevant EF Core metadata at design time. // For details, please refer to https://supportcenter.devexpress.com/ticket/details/t933891. public class ClassLibrary1ContextInitializer : DbContextTypesInfoInitializerBase { protected override DbContext CreateDbContext() { var optionsBuilder = new DbContextOptionsBuilder<ClassLibrary1EFCoreDbContext>() .UseSqlServer(";") .UseChangeTrackingProxies() .UseObjectSpaceLinkProxies(); return new ClassLibrary1EFCoreDbContext(optionsBuilder.Options); } } //This factory creates DbContext for design-time services. For example, it is required for database migration. public class ClassLibrary1DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ClassLibrary1EFCoreDbContext> { public ClassLibrary1EFCoreDbContext CreateDbContext(string[] args) { throw new InvalidOperationException("Make sure that the database connection string and connection provider are correct. After that, uncomment the code below and remove this exception."); //var optionsBuilder = new DbContextOptionsBuilder<ClassLibraryEFCoreDbContext>(); //optionsBuilder.UseSqlServer("Integrated Security=SSPI;Pooling=false;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB1"); //optionsBuilder.UseChangeTrackingProxies(); //optionsBuilder.UseObjectSpaceLinkProxies(); //return new ClassLibraryEFCoreDbContext(optionsBuilder.Options); } } [TypesInfoInitializer(typeof(ClassLibrary1ContextInitializer))] public class ClassLibrary1EFCoreDbContext : DbContext { public ClassLibrary1EFCoreDbContext(DbContextOptions<ClassLibrary1EFCoreDbContext> options) : base(options) { } public DbSet<ModuleInfo1> ModulesInfo1 { get; set; } public DbSet<PersistentClass1> PersistentClasses1 { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues); } }
EFCore/ClassLibrary1/PersistentClass1.cs
C#
using System; using DevExpress.Persistent.Base; using DevExpress.Persistent.BaseImpl.EF; namespace ClassLibrary1 { [DefaultClassOptions] public class PersistentClass1 : BaseObject { public virtual string PersistentProperty1A { get; set; } public virtual string PersistentProperty1B { get; set; } } }
EFCore/ClassLibrary1/XafModule1.cs
C#
using System; using DevExpress.Data.Filtering; using DevExpress.ExpressApp; using DevExpress.ExpressApp.ApplicationBuilder; using DevExpress.ExpressApp.Updating; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using DevExpress.ExpressApp.ApplicationBuilder.Internal; using System.Configuration; using Microsoft.Extensions.Configuration; namespace ClassLibrary1 { public class XafModule1 : ModuleBase { const string ConnectionStringName = "ConnectionString1"; public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { XafModuleUpdater1 updater = new XafModuleUpdater1(objectSpace, versionFromDB); return new ModuleUpdater[] { updater }; } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderBuilder<TContext> objectSpaceProviderBuilder) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName]?.ConnectionString; objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<ClassLibrary1EFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderServiceBasedBuilder<TContext> objectSpaceProviderBuilder, IConfiguration configuration) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = configuration.GetConnectionString(ConnectionStringName); objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<ClassLibrary1EFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } static void SetupDbContext(DbContextOptionsBuilder options, string connectionString) { // Uncomment this code to use an in-memory database. This database is recreated each time the server starts. With the in-memory database, you don't need to make a migration when the data model is changed. // Do not use this code in production environment to avoid data loss. // We recommend that you refer to the following help topic before you use an in-memory database: https://docs.microsoft.com/en-us/ef/core/testing/in-memory //options.UseInMemoryDatabase("InMemory"); ArgumentNullException.ThrowIfNull(connectionString); options.UseSqlServer(connectionString); options.UseChangeTrackingProxies(); options.UseObjectSpaceLinkProxies(); options.UseLazyLoadingProxies(); } } public class XafModuleUpdater1 : ModuleUpdater { public XafModuleUpdater1(IObjectSpace objectSpace, Version currentDBVersion) : base(objectSpace, currentDBVersion) { } public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); // Check whether it is a valid ObjectSpace to create objects of a certain type. if (ObjectSpace.CanInstantiate(typeof(PersistentClass1))) { string str = "test1"; PersistentClass1 theObject = ObjectSpace.FindObject<PersistentClass1>(CriteriaOperator.Parse("PersistentProperty1A = ?", str)); if (theObject == null) { theObject = ObjectSpace.CreateObject<PersistentClass1>(); theObject.PersistentProperty1A = str; theObject.PersistentProperty1B = str; } ObjectSpace.CommitChanges(); } } } }
EFCore/ClassLibrary2/ClassLibrary2DbContext.cs
C#
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using DevExpress.ExpressApp.Design; using DevExpress.ExpressApp.EFCore.DesignTime; namespace ClassLibrary2; // This code allows our Model Editor to get relevant EF Core metadata at design time. // For details, please refer to https://supportcenter.devexpress.com/ticket/details/t933891. public class ClassLibrary2ContextInitializer : DbContextTypesInfoInitializerBase { protected override DbContext CreateDbContext() { var optionsBuilder = new DbContextOptionsBuilder<ClassLibrary2EFCoreDbContext>() .UseSqlServer(";") .UseChangeTrackingProxies() .UseObjectSpaceLinkProxies(); return new ClassLibrary2EFCoreDbContext(optionsBuilder.Options); } } //This factory creates DbContext for design-time services. For example, it is required for database migration. public class ClassLibrary2DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ClassLibrary2EFCoreDbContext> { public ClassLibrary2EFCoreDbContext CreateDbContext(string[] args) { throw new InvalidOperationException("Make sure that the database connection string and connection provider are correct. After that, uncomment the code below and remove this exception."); //var optionsBuilder = new DbContextOptionsBuilder<ClassLibraryEFCoreDbContext>(); //optionsBuilder.UseSqlServer("Integrated Security=SSPI;Pooling=false;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB1"); //optionsBuilder.UseChangeTrackingProxies(); //optionsBuilder.UseObjectSpaceLinkProxies(); //return new ClassLibraryEFCoreDbContext(optionsBuilder.Options); } } [TypesInfoInitializer(typeof(ClassLibrary2ContextInitializer))] public class ClassLibrary2EFCoreDbContext : DbContext { public ClassLibrary2EFCoreDbContext(DbContextOptions<ClassLibrary2EFCoreDbContext> options) : base(options) { } public DbSet<PersistentClass2> PersistentClasses2 { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues); } }
EFCore/ClassLibrary2/PersistentClass2.cs
C#
using System; using DevExpress.Persistent.Base; using DevExpress.Persistent.BaseImpl.EF; namespace ClassLibrary2 { [DefaultClassOptions] public class PersistentClass2 : BaseObject { public virtual string PersistentPropertyX { get; set; } } }
EFCore/ClassLibrary2/XafModule2.cs
C#
using System; using DevExpress.Data.Filtering; using DevExpress.ExpressApp; using DevExpress.ExpressApp.ApplicationBuilder; using DevExpress.ExpressApp.Updating; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using DevExpress.ExpressApp.ApplicationBuilder.Internal; using System.Configuration; using Microsoft.Extensions.Configuration; namespace ClassLibrary2 { public class XafModule2 : ModuleBase { const string ConnectionStringName = "ConnectionString2"; public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { XafModuleUpdater2 updater = new XafModuleUpdater2(objectSpace, versionFromDB); return new ModuleUpdater[] { updater }; } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderBuilder<TContext> objectSpaceProviderBuilder) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName]?.ConnectionString; objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<ClassLibrary2EFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderServiceBasedBuilder<TContext> objectSpaceProviderBuilder, IConfiguration configuration) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = configuration.GetConnectionString(ConnectionStringName); objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<ClassLibrary2EFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } static void SetupDbContext(DbContextOptionsBuilder options, string connectionString) { // Uncomment this code to use an in-memory database. This database is recreated each time the server starts. With the in-memory database, you don't need to make a migration when the data model is changed. // Do not use this code in production environment to avoid data loss. // We recommend that you refer to the following help topic before you use an in-memory database: https://docs.microsoft.com/en-us/ef/core/testing/in-memory //options.UseInMemoryDatabase("InMemory"); ArgumentNullException.ThrowIfNull(connectionString); options.UseSqlServer(connectionString); options.UseChangeTrackingProxies(); options.UseObjectSpaceLinkProxies(); options.UseLazyLoadingProxies(); } } public class XafModuleUpdater2 : ModuleUpdater { public XafModuleUpdater2(IObjectSpace objectSpace, Version currentDBVersion) : base(objectSpace, currentDBVersion) { } public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); // Check whether it is a valid ObjectSpace to create objects of a certain type. if (ObjectSpace.CanInstantiate(typeof(PersistentClass2))) { string str = "test2"; PersistentClass2 theObject = ObjectSpace.FindObject<PersistentClass2>(CriteriaOperator.Parse("PersistentPropertyX = ?", str)); if (theObject == null) { theObject = ObjectSpace.CreateObject<PersistentClass2>(); theObject.PersistentPropertyX = str; } ObjectSpace.CommitChanges(); } } } }
EFCore/CommonModule/Module.cs
C#
using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Updating; using DevExpress.ExpressApp.ApplicationBuilder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System.Configuration; using CommonModule.BusinessObjects; using DevExpress.ExpressApp.ApplicationBuilder.Internal; using Microsoft.Extensions.Configuration; namespace CommonModule; // For more typical usage scenarios, be sure to check out https://docs.devexpress.com/eXpressAppFramework/DevExpress.ExpressApp.ModuleBase. public sealed class CommonModule : ModuleBase { #if EASYTEST const string ConnectionStringName = "EasyTestConnectionString"; #else const string ConnectionStringName = "ConnectionString0"; #endif public CommonModule() { // // CommonModuleModule // AdditionalExportedTypes.Add(typeof(ApplicationUser)); AdditionalExportedTypes.Add(typeof(DevExpress.Persistent.BaseImpl.EF.PermissionPolicy.PermissionPolicyRole)); AdditionalExportedTypes.Add(typeof(DevExpress.Persistent.BaseImpl.EF.ModelDifference)); AdditionalExportedTypes.Add(typeof(DevExpress.Persistent.BaseImpl.EF.ModelDifferenceAspect)); RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule)); RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Security.SecurityModule)); RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule)); RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Validation.ValidationModule)); DevExpress.ExpressApp.Security.SecurityModule.UsedExportedTypes = DevExpress.Persistent.Base.UsedExportedTypes.Custom; } public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB); return new ModuleUpdater[] { updater }; } public override void Setup(XafApplication application) { base.Setup(application); // Manage various aspects of the application UI and behavior at the module level. } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderBuilder<TContext> objectSpaceProviderBuilder) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName]?.ConnectionString; objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<CommonModuleEFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } public static void SetupObjectSpace<TContext>(IObjectSpaceProviderServiceBasedBuilder<TContext> objectSpaceProviderBuilder, IConfiguration configuration) where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection> { string connectionString = configuration.GetConnectionString(ConnectionStringName); objectSpaceProviderBuilder.AddSecuredEFCore() .WithDbContext<CommonModuleEFCoreDbContext>((application, options) => SetupDbContext(options, connectionString)); } static void SetupDbContext(DbContextOptionsBuilder options, string connectionString) { // Uncomment this code to use an in-memory database. This database is recreated each time the server starts. With the in-memory database, you don't need to make a migration when the data model is changed. // Do not use this code in production environment to avoid data loss. // We recommend that you refer to the following help topic before you use an in-memory database: https://docs.microsoft.com/en-us/ef/core/testing/in-memory //options.UseInMemoryDatabase("InMemory"); ArgumentNullException.ThrowIfNull(connectionString); options.UseSqlServer(connectionString); options.UseChangeTrackingProxies(); options.UseObjectSpaceLinkProxies(); options.UseLazyLoadingProxies(); } }
EFCore/TwoModelsForDifferentDatabases.Blazor.Server/Startup.cs
C#
using DevExpress.ExpressApp.Security; using DevExpress.ExpressApp.ApplicationBuilder; using DevExpress.ExpressApp.Blazor.ApplicationBuilder; using DevExpress.ExpressApp.Blazor.Services; using DevExpress.Persistent.Base; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Components.Server.Circuits; using Microsoft.EntityFrameworkCore; using TwoModelsForDifferentDatabases.Blazor.Server.Services; using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy; using DevExpress.ExpressApp.Core; namespace TwoModelsForDifferentDatabases.Blazor.Server; public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddSingleton(typeof(Microsoft.AspNetCore.SignalR.HubConnectionHandler<>), typeof(ProxyHubConnectionHandler<>)); services.AddRazorPages(); services.AddServerSideBlazor(); services.AddHttpContextAccessor(); services.AddScoped<CircuitHandler, CircuitHandlerProxy>(); services.AddXaf(Configuration, builder => { builder.UseApplication<TwoModelsForDifferentDatabasesBlazorApplication>(); builder.Modules .AddConditionalAppearance() .AddValidation(options => { options.AllowValidationDetailsAccess = false; }) .Add<CommonModule.CommonModule>() .Add<TwoModelsForDifferentDatabasesBlazorModule>() .Add<ClassLibrary1.XafModule1>() .Add<ClassLibrary2.XafModule2>(); CommonModule.CommonModule.SetupObjectSpace(builder.ObjectSpaceProviders, Configuration); ClassLibrary1.XafModule1.SetupObjectSpace(builder.ObjectSpaceProviders, Configuration); ClassLibrary2.XafModule2.SetupObjectSpace(builder.ObjectSpaceProviders, Configuration); builder.ObjectSpaceProviders.AddNonPersistent(); builder.Security .UseIntegratedMode(options => { options.RoleType = typeof(PermissionPolicyRole); // ApplicationUser descends from PermissionPolicyUser and supports the OAuth authentication. For more information, refer to the following topic: https://docs.devexpress.com/eXpressAppFramework/402197 // If your application uses PermissionPolicyUser or a custom user type, set the UserType property as follows: options.UserType = typeof(CommonModule.BusinessObjects.ApplicationUser); // ApplicationUserLoginInfo is only necessary for applications that use the ApplicationUser user type. // If you use PermissionPolicyUser or a custom user type, comment out the following line: options.UserLoginInfoType = typeof(CommonModule.BusinessObjects.ApplicationUserLoginInfo); }) .AddPasswordAuthentication(options => { options.IsSupportChangePassword = true; }); }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { options.LoginPath = "/LoginPage"; }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if(env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. To change this for production scenarios, see: https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseRequestLocalization(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseXaf(); app.UseEndpoints(endpoints => { endpoints.MapXafEndpoints(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); endpoints.MapControllers(); }); } }
EFCore/TwoModelsForDifferentDatabases.Blazor.Server/appsettings.json
JSON
{ "ConnectionStrings": { "ConnectionString0": "Integrated Security=SSPI;Pooling=false;MultipleActiveResultSets=true;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB0_EFCore", "ConnectionString1": "Integrated Security=SSPI;Pooling=false;MultipleActiveResultSets=true;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB1_EFCore", "ConnectionString2": "Integrated Security=SSPI;Pooling=false;MultipleActiveResultSets=true;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB2_EFCore", "EasyTestConnectionString": "Integrated Security=SSPI;Pooling=false;MultipleActiveResultSets=true;Data Source=(localdb)\\mssqllocaldb;Initial Catalog=DB0_EFCore_EasyTest" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information", "DevExpress.ExpressApp": "Information" } }, "AllowedHosts": "*", "DevExpress": { "ExpressApp": { "Languages": "en-US;", "ShowLanguageSwitcher": false, "ThemeSwitcher": { "DefaultItemName": "Office White", // This line is changed according to the following BC: https://supportcenter.devexpress.com/internal/ticket/details/t1090666, "ShowSizeModeSwitcher": true, "Groups": [ { "Caption": "DevExpress Themes", "Items": [ { "Caption": "Blazing Berry", "Url": "_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css", "Color": "#5c2d91" }, { "Caption": "Blazing Dark", "Url": "_content/DevExpress.Blazor.Themes/blazing-dark.bs5.min.css", "Color": "#46444a" }, { "Caption": "Office White", "Url": "_content/DevExpress.Blazor.Themes/office-white.bs5.min.css", "Color": "#fe7109" }, { "Caption": "Purple", "Url": "_content/DevExpress.Blazor.Themes/purple.bs5.min.css", "Color": "#7989ff" } ] } ] } } } }
EFCore/TwoModelsForDifferentDatabases.Win/Startup.cs
C#
using System.Configuration; using DevExpress.ExpressApp; using DevExpress.ExpressApp.ApplicationBuilder; using DevExpress.ExpressApp.Win.ApplicationBuilder; using DevExpress.ExpressApp.Win; using Microsoft.EntityFrameworkCore; using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy; using DevExpress.ExpressApp.Design; namespace TwoModelsForDifferentDatabases.Win; public class ApplicationBuilder : IDesignTimeApplicationFactory { public static WinApplication BuildApplication(string connectionString) { var builder = WinApplication.CreateBuilder(); builder.UseApplication<TwoModelsForDifferentDatabasesWindowsFormsApplication>(); builder.Modules .AddConditionalAppearance() .AddValidation(options => { options.AllowValidationDetailsAccess = false; }) .Add<CommonModule.CommonModule>() .Add<TwoModelsForDifferentDatabasesWinModule>() .Add<ClassLibrary1.XafModule1>() .Add<ClassLibrary2.XafModule2>(); CommonModule.CommonModule.SetupObjectSpace(builder.ObjectSpaceProviders); ClassLibrary1.XafModule1.SetupObjectSpace(builder.ObjectSpaceProviders); ClassLibrary2.XafModule2.SetupObjectSpace(builder.ObjectSpaceProviders); builder.ObjectSpaceProviders.AddNonPersistent(); builder.Security .UseIntegratedMode(options => { options.RoleType = typeof(PermissionPolicyRole); options.UserType = typeof(CommonModule.BusinessObjects.ApplicationUser); options.UserLoginInfoType = typeof(CommonModule.BusinessObjects.ApplicationUserLoginInfo); }) .UsePasswordAuthentication(); builder.AddBuildStep(application => { application.ConnectionString = connectionString; #if DEBUG if(System.Diagnostics.Debugger.IsAttached && application.CheckCompatibilityType == CheckCompatibilityType.DatabaseSchema) { application.DatabaseUpdateMode = DatabaseUpdateMode.UpdateDatabaseAlways; } #endif }); var winApplication = builder.Build(); return winApplication; } XafApplication IDesignTimeApplicationFactory.Create() => BuildApplication(XafApplication.DesignTimeConnectionString); }
EFCore/TwoModelsForDifferentDatabases.Win/App.config
Code
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System"> <section name="DevExpress.LookAndFeel.Design.AppSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <applicationSettings> <DevExpress.LookAndFeel.Design.AppSettings> <setting name="DPIAwarenessMode" serializeAs="String"> <value>System</value> </setting> </DevExpress.LookAndFeel.Design.AppSettings> </applicationSettings> <appSettings> <add key="Modules" value="" /> <add key="NewVersionServer" value="" /> <add key="EnableDiagnosticActions" value="False" /> <!-- Use the one of predefined values: None, ApplicationFolder, CurrentUserApplicationDataFolder. The default value is ApplicationFolder. <add key="TraceLogLocation" value="CurrentUserApplicationDataFolder"/> <add key="UserModelDiffsLocation" value="CurrentUserApplicationDataFolder"/> <add key="Languages" value="de;es;ja"/> --> <!-- Use one of the following predefined values: 0-Off, 1-Errors, 2-Warnings, 3-Info, 4-Verbose. The default value is 3. --> <add key="eXpressAppFrameworkTraceLevel" value="3" /> </appSettings> <connectionStrings> <add name="EasyTestConnectionString" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=true;Data Source=(localdb)\mssqllocaldb;Initial Catalog=DB0_EFCore_EasyTest" providerName="Microsoft.Data.SqlClient" /> <add name="ConnectionString0" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Data Source=(localdb)\mssqllocaldb;Initial Catalog=DB0_EFCore" providerName="Microsoft.Data.SqlClient" /> <add name="ConnectionString1" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Data Source=(localdb)\mssqllocaldb;Initial Catalog=DB1_EFCore" providerName="Microsoft.Data.SqlClient" /> <add name="ConnectionString2" connectionString="Integrated Security=SSPI;MultipleActiveResultSets=True;Data Source=(localdb)\mssqllocaldb;Initial Catalog=DB2_EFCore" providerName="Microsoft.Data.SqlClient" /> <!-- Use the following connection string to connect to a Jet (Microsoft Access) database: <add name="ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=TwoModelsForDifferentDatabases.mdb;Mode=Share Deny None;"/> --> </connectionStrings> </configuration>

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.