Session.CreateObjectTypeRecordsAsync(CancellationToken) Method
Asynchronously stores valid persistent types for all the types which are defined within the assemblies that have been loaded in the current application domain.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public Task CreateObjectTypeRecordsAsync(
CancellationToken cancellationToken = default(CancellationToken)
)
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
cancellation |
Cancellation |
null | A Cancellation |
#Returns
Type | Description |
---|---|
Task | A Task that stores valid persistent types for all the types which are defined within the assemblies that have been loaded in the current application domain. |
#Remarks
For thread-safe data access layers (see ThreadSafeDataLayer) to function correctly, it’s necessary to provide complete metadata information on the persistent objects in a data store before performing any operations with persistent objects. Call the CreateObjectTypeRecordsAsync method and pass persistent class metadata information as the types parameter to store valid persistent types for the corresponding persistent objects. This creates all the necessary records within a special table called XPObjectType which is used to support object polymorphism.
using System.Threading;
using System.Threading.Tasks;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
// ...
public async Task CreateDatabase(string connectionString) {
using(IDataLayer dal = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema)) {
UnitOfWork uow = new UnitOfWork(dal);
await uow.UpdateSchemaAsync(CancellationToken.None);
await uow.CreateObjectTypeRecordsAsync(CancellationToken.None);
}
}