Back to Devexpress

XAF0031: Add the UseChangeTrackingProxies() call for automatic UI updates

expressappframework-404519-debugging-testing-and-error-handling-code-diagnostics-xaf0031.md

latest3.3 KB
Original Source

XAF0031: Add the UseChangeTrackingProxies() call for automatic UI updates

  • Nov 08, 2024

Severity: Warning

Enable the DbContextOptionsBuilder.UseChangeTrackingProxies() option for automatic UI updates and change notifications from business object setters.

For more information, refer to the following topic: PropertyChanged and CollectionChanged Event in Entity Framework Core.

Examples

See the Startup.cs file in YourSolutionName.Blazor.Server and YourSolutionName.Win projects:

Invalid Code

csharp
public void ConfigureServices(IServiceCollection services) {
    services.AddXaf(Configuration, builder => {
        // ...
        builder.ObjectSpaceProviders
            .AddEFCore(options => options.PreFetchReferenceProperties())
                .WithDbContext<YourSolutionName.Module.BusinessObjects.YourSolutionNameEFCoreDbContext>((serviceProvider, options) => {
                    // ...
                    options.UseSqlServer(connectionString);
                    options.UseObjectSpaceLinkProxies();
                    options.UseLazyLoadingProxies();
                })
            .AddNonPersistent();
    });
}
csharp
public static WinApplication BuildApplication(string connectionString) {
    // ...
    builder.ObjectSpaceProviders
        .AddEFCore(options => options.PreFetchReferenceProperties())
            .WithDbContext<YourSolutionName.Module.BusinessObjects.YourSolutionNameEFCoreDbContext>((application, options) => {                    
                options.UseSqlServer(connectionString);
                options.UseObjectSpaceLinkProxies();
            })
        .AddNonPersistent();
    // ...
}

Valid Code

csharp
public void ConfigureServices(IServiceCollection services) {
    services.AddXaf(Configuration, builder => {
        // ...
        builder.ObjectSpaceProviders
            .AddEFCore(options => options.PreFetchReferenceProperties())
                .WithDbContext<YourSolutionName.Module.BusinessObjects.YourSolutionNameEFCoreDbContext>((serviceProvider, options) => {
                    // ...
                    options.UseSqlServer(connectionString);
                    options.UseChangeTrackingProxies();
                    options.UseObjectSpaceLinkProxies();
                    options.UseLazyLoadingProxies();
                })
            .AddNonPersistent();
    });
}
csharp
public static WinApplication BuildApplication(string connectionString) {
    // ...
    builder.ObjectSpaceProviders
        .AddEFCore(options => options.PreFetchReferenceProperties())
            .WithDbContext<YourSolutionName.Module.BusinessObjects.YourSolutionNameEFCoreDbContext>((application, options) => {                    
                options.UseSqlServer(connectionString);
                options.UseChangeTrackingProxies();
                options.UseObjectSpaceLinkProxies();
            })
        .AddNonPersistent();
    // ...
}