Back to Devexpress

XpoDefault.DataLayer Property

xpo-devexpress-dot-xpo-dot-xpodefault.md

latest7.3 KB
Original Source

XpoDefault.DataLayer Property

Gets or sets the default data access layer which is used by Session objects by default, to access a data store.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public static IDataLayer DataLayer { get; set; }
vb
Public Shared Property DataLayer As IDataLayer

Property Value

TypeDescription
IDataLayer

An object which implements the IDataLayer interface; null - in this case, every new session will create and use its own data layer.

|

Example

This example demonstrates how to create a data layer that will be used by all Session objects.

The XpoDefault.DataLayer property’s value is null by default. XPO creates a new data layer for each session when the session is connected to a data store.

In this example, a data layer (represented by the SimpleDataLayer class object) is created and assigned to the XpoDefault.DataLayer property using the XpoDefault.GetDataLayer method.

In this case, newly created sessions will use this data layer. The sessions’ Session.Connection and Session.ConnectionString properties are not initialized.

csharp
using DevExpress.Data.DB;
using DevExpress.Xpo;

string forcedConnectionString = ...;
XpoDefault.DataLayer = XpoDefault.GetDataLayer(forcedConnectionString, 
    AutoCreateOption.DatabaseAndSchema);
vb
Imports DevExpress.Data.DB
Imports DevExpress.Xpo

Dim forcedConnectionString As String = ...
XpoDefault.DataLayer = XpoDefault.GetDataLayer(forcedConnectionString, _
    AutoCreateOption.DatabaseAndSchema)

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataLayer property.

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.

how-to-bind-wpf-grid-to-data/CS/CodeBehind/XPO/InfiniteAsyncSource/Issues/ConnectionHelper.cs#L16

csharp
public static void Connect() {
    XpoDefault.DataLayer = CreateDataLayer(true);
}

wpf-data-grid-implement-crud-operations/CS/CodeBehind/XPO/InfiniteAsyncSource/Issues/ConnectionHelper.cs#L16

csharp
public static void Connect() {
    XpoDefault.DataLayer = CreateDataLayer(true);
}

XPO_how-to-make-user-friendly-object-identifiers-e825/CS/Program.cs#L17

csharp
static void Main(string[] args) {
    XpoDefault.DataLayer = XpoDefault.GetDataLayer(AutoCreateOption.DatabaseAndSchema);
    Do("A");

CriteriaOperatorsCheatSheet/CS/CriteriaOperatorCheatSheet/ConnectionHelper.cs#L37

csharp
dictionary.GetDataStoreSchema(persistentTypes);
    XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider);
} else {

XPO_how-to-implement-a-distributed-object-layer-service-working-via-wcf-e5072/CS/ConsoleApplication1/Program.cs#L16

csharp
serializableObjectLayer.CanLoadCollectionObjects.ToString();
XpoDefault.DataLayer = null;
XpoDefault.Session = null;

how-to-bind-wpf-grid-to-data/VB/CodeBehind/XPO/InfiniteAsyncSource/Issues/ConnectionHelper.vb#L12

vb
Public Sub Connect()
    XpoDefault.DataLayer = CreateDataLayer(True)
End Sub

XPO_how-to-make-user-friendly-object-identifiers-e825/VB/Program.vb#L18

vb
Shared Sub Main(ByVal args() As String)
    XpoDefault.DataLayer = XpoDefault.GetDataLayer(AutoCreateOption.DatabaseAndSchema)
    [Do]("A")

XPO_how-to-implement-a-distributed-object-layer-service-working-via-wcf-e5072/VB/ConsoleApplication1/Program.vb#L15

vb
serializableObjectLayer.CanLoadCollectionObjects.ToString()
XpoDefault.DataLayer = Nothing
XpoDefault.Session = Nothing

XPO_how-to-generate-a-sequential-number-for-a-business-object-within-a-database-transaction-e2620/VB/ExplicitUnitOfWorkDemo/Program.vb#L24

vb
DatabaseHelper.DataLayer = XpoDefault.GetDataLayer(cs, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema)
XpoDefault.DataLayer = DatabaseHelper.DataLayer
DatabaseHelper.SequenceDataLayer = XpoDefault.GetDataLayer(cs, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema)

XPO_how-to-implement-custom-aggregates/VB/XpoCustomAggregate/DataAccess/ConnectionHelper.vb#L13

vb
Public Sub Connect(Optional ByVal threadSafe As Boolean = True)
    XpoDefault.DataLayer = CreateDataLayer(threadSafe)
End Sub

See Also

DataLayer

XpoDefault Class

XpoDefault Members

DevExpress.Xpo Namespace