Back to Devexpress

EFCoreObjectSpace Class

expressappframework-devexpress-dot-expressapp-dot-efcore.md

latest4.3 KB
Original Source

EFCoreObjectSpace Class

An Object Space used for data manipulation in EF Core-based applications that do not use the Security System.

Namespace : DevExpress.ExpressApp.EFCore

Assembly : DevExpress.ExpressApp.EFCore.v25.2.dll

NuGet Package : DevExpress.ExpressApp.EFCore

Declaration

csharp
public class EFCoreObjectSpace :
    CompositeObjectSpace,
    IQuerySupport,
    ISupportServerViews,
    ISupportCriteriaCompiler,
    ISupportServerExpressionEvaluator,
    IDataLockingManager,
    IOptimisticLockHandlingManager
vb
Public Class EFCoreObjectSpace
    Inherits CompositeObjectSpace
    Implements IQuerySupport,
               ISupportServerViews,
               ISupportCriteriaCompiler,
               ISupportServerExpressionEvaluator,
               IDataLockingManager,
               IOptimisticLockHandlingManager

Remarks

XAF creates Object Spaces of the EFCoreObjectSpace type if an application calls the AddEFCore method at startup.

In XAF application, use the XafApplication.CreateObjectSpace method to create this Object Space if the default Object Space Provider is EFCoreObjectSpaceProvider<TDbContext>.

The following example demonstrates how to use EFCoreObjectSpaceProvider<TDbContext> to create EFCoreObjectSpace in a non-XAF application.

csharp
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.EFCore;
using Microsoft.EntityFrameworkCore;
using System;
// ...
class Program {
    static void Main() {
        var objectSpaceProvider = 
            new EFCoreObjectSpaceProvider<ApplicationDbContext>(
            (builder, _) => builder.UseConnectionString(
                ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString));
        IObjectSpace objectSpace = objectSpaceProvider.CreateObjectSpace();
        // ...
    }
}

You can find the full example in the following GitHub repository: How to use the Integrated mode of the Security System in non-XAF applications (EF Core).

To learn more about Object Spaces, refer to the BaseObjectSpace class description.

Important Note

The EF Core Object Space does not support top level agregate functions in criteria. Use Free Joins instead.

csharp
// Invalid code:
// int totalNumber = (int)ObjectSpace.Evaluate(typeof(Department), CriteriaOperator.Parse("Sum([NumberOfEmployees])"), null);
// ...
// Valid code:
int totalNumber = (int)ObjectSpace.Evaluate(typeof(Department), CriteriaOperator.Parse("[<Department>].Sum([NumberOfEmployees])"), null);

Implements

IObjectSpace

Inheritance

Object BaseObjectSpace CompositeObjectSpace EFCoreObjectSpace SecuredEFCoreObjectSpace

See Also

EFCoreObjectSpace Members

DevExpress.ExpressApp.EFCore Namespace