XafApplication.DatabaseVersionMismatch Event
Occurs when the database should be synchronized with the application version.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v25.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Event Data
The DatabaseVersionMismatch event's data class is DatabaseVersionMismatchEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CompatibilityError | Returns the database and application compatibility error. |
| Handled | Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs. |
| Updater | Provides access to the Database Updater. Use the object returned by this property to update the application database. |
Remarks
XAF checks database and application compatibility when the application accesses the database. After checking, the DatabaseVersionMismatch event fires in the following cases:
- The database cannot be opened.
The CompatibilityError property returnsCompatibilityUnableToOpenDatabaseError. - The database version is older than the application version.
The CompatibilityError property returnsCompatibilityDatabaseIsOldError. - The DatabaseUpdateMode property is set to
UpdateDatabaseAlways.
The CompatibilityError property returnsnull.
Handle this event to update the database. Use the Updater parameter to access the Database Updater object. Set the Handled parameter to true, to prevent other database version updates.
The DevExpress Template Kit handles the DatabaseVersionMismatch event in new Blazor, Web API, and WinForms projects to keep the application and database versions synchronized. If the database version is older than the application’s version, the event triggers at startup, and the handler runs the Database Updater’s Update method. Rewrite this event handler if you need to implement custom logic.
- SolutionName.Blazor.Server\BlazorApplication.cs
- SolutionName.WebApi\Startup.cs
- SolutionName.Win\WinApplication.cs
public class SolutionNameBlazorApplication : BlazorApplication {
public SolutionNameBlazorApplication() {
DatabaseVersionMismatch += SolutionNameBlazorApplication_DatabaseVersionMismatch;
// ...
}
void SolutionNameBlazorApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e) {
e.Updater.Update();
e.Handled = true;
// ...
Important
If the application includes the Middle Tier Server Application, the compatibility check must be performed at the server side. Client applications (Blazor, Web API, and WinForms) should throw an exception when the DatabaseVersionMismatch event occurs.
When you use the Template Kit to create an application with a Middle Tier Security server, the kit handles the DatabaseVersionMismatch event in the Middle Tier Application.
// File: SolutionName.MiddleTier\Startup.cs
builder.AddBuildStep(application => {
application.CheckCompatibilityType = DevExpress.ExpressApp.CheckCompatibilityType.DatabaseSchema;
if (application.CheckCompatibilityType == CheckCompatibilityType.DatabaseSchema) {
application.DatabaseUpdateMode = DatabaseUpdateMode.UpdateDatabaseAlways;
application.DatabaseVersionMismatch += (s, e) => {
e.Updater.Update();
e.Handled = true;
};
}
//...
The DatabaseVersionMismatch event does not occur if you handle the CustomCheckCompatibility event.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the DatabaseVersionMismatch event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.