Session.UpdateSchemaAsync(CancellationToken, Boolean, XPClassInfo[]) Method
Asynchronously updates the database schema to support the persistence of the objects with the specified metadata information.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public Task<UpdateSchemaResult> UpdateSchemaAsync(
CancellationToken cancellationToken,
bool doNotCreateIfFirstTableNotExist,
params XPClassInfo[] types
)
#Parameters
Name | Type | Description |
---|---|---|
cancellation |
Cancellation |
A Cancellation |
do |
Boolean | true if the schema should not be created when the table that corresponds to the first item in the types array doesn’t exist in the data store; otherwise, false. |
types | XPClass |
An array of XPClass |
#Returns
Type | Description |
---|---|
Task<Update |
A Task |
#Remarks
using System.Threading;
using System.Threading.Tasks;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Metadata;
// ...
public async Task CreateDatabase(string connectionString, params XPClassInfo[] persistentClasses) {
using(IDataLayer dal = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema)) {
UnitOfWork uow = new UnitOfWork(dal);
await uow.UpdateSchemaAsync(CancellationToken.None, persistentClasses);
await uow.CreateObjectTypeRecordsAsync(CancellationToken.None, true, persistentClasses);
}
}