The requested page is not available for the requested platform. You are viewing the content for Default platform.

ThreadSafeDataLayer Class

Implements a data layer that allows multiple threads to access data in a data store at the same time.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v18.2.dll

Declaration

public class ThreadSafeDataLayer :
    BaseDataLayer,
    ICommandChannel
Public Class ThreadSafeDataLayer
    Inherits BaseDataLayer
    Implements ICommandChannel

Remarks

This class implements a data access layer that allows multiple threads to access data in a data store at the same time. See the Data Access Layer concept for more information on using data access layers.

Note

Prior to performing any operations with persistent objects in a data store using thread-safe data access layers, call the Session.CreateObjectTypeRecords method to obtain complete metadata information on the persistent objects.

Examples

The following code demonstrates how to initialize the ThreadSafeDataLayer component. The XPDictionary.GetDataStoreSchema method is called to force creating the persistent class metadata information in advance. This is a required step.

The XPDictionary.GetDataStoreSchema method allows you to specify the array of class types or assemblies where persistent classes are declared. In this example, it is assumed that all persistent classes are declared in the assembly that contains the code that is currently being executed.

private static IDataLayer GetDataLayer() {
   XpoDefault.Session = null;
   string conn = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
   conn = XpoDefault.GetConnectionPoolString(conn);
   XPDictionary dict = new ReflectionDictionary();
   IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);
    dict.GetDataStoreSchema(System.Reflection.Assembly.GetExecutingAssembly());
   IDataLayer dl = new ThreadSafeDataLayer(dict, store);
   return dl;
}

Inheritance

Object
DevExpress.Xpo.Helpers.BaseDataLayer
ThreadSafeDataLayer

Implements

DevExpress.Xpo.Helpers.IDataLayerProvider
DevExpress.Xpo.Metadata.Helpers.IXPDictionaryProvider
DevExpress.Xpo.Helpers.ICommandChannel
See Also