BootstrapCardViewBuilderBase<T>.BindToXPO<TEntity>(XPQuery<TEntity>) Method
Establishes a server-mode data binding via DevExpress eXpress Persistent Objects for .NET (XPO) ORM.
Namespace: DevExpress.AspNetCore.Bootstrap
Assembly:
DevExpress.AspNetCore.Bootstrap.v18.2.dll
Declaration
public T BindToXPO<TEntity>(
XPQuery<TEntity> query
)
Public Function BindToXPO(Of TEntity)(
query As XPQuery(Of TEntity)
) As T
Parameters
Name |
Type |
Description |
query |
XPQuery<TEntity> |
An object of the XPQuery class that specifies a query.
|
Type Parameters
Name |
Description |
TEntity |
The type of the data in a dataset.
|
Returns
Type |
Description |
T |
A reference to this instance after the operation is completed.
|
IMPORTANT
Bootstrap Controls for ASP.NET Core are in maintenance mode. We don’t add new controls or develop new functionality for this product line. Our recommendation is to use the ASP.NET Core Controls suite.
The Card View control supports data binding in server mode, which is designed to work with large datasets. This technique significantly improves the control’s speed and responsiveness.
The BindToXPO method is used to establish server-mode data binding using the DevExpress eXpress Persistent Objects for .NET (XPO) ORM. The following code demonstrates the described functionality in detail.
@model XPQuery<XPEmail>
@(Html.DevExpress()
.BootstrapCardView<XPEmail>("cardViewWithXPO")
.KeyFieldName(k => k.ID)
.Columns(columns => {
columns.Add(c => c.From);
columns.Add(c => c.Subject);
})
.Routes(routes => routes
.MapRoute(r => r
.Action("BindingToXPOPartial")
.Controller("CardView")))
.BindToXPO(Model))
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace DevExpress.AspNetCore.Demos {
public partial class CardViewController : Controller {
protected LargeDatabaseUnitOfWork LargeDatabaseUnitOfWork => HttpContext.RequestServices.GetService<LargeDatabaseUnitOfWork>();
public IActionResult BindingToXPO() {
return PartialView("DataBinding/BindingToXPO", LargeDatabaseUnitOfWork.Emails);
}
public IActionResult BindingToXPOPartial() {
return PartialView("DataBinding/BindingToXPOPartial", LargeDatabaseUnitOfWork.Emails);
}
}
}
using System;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Metadata;
using Microsoft.Extensions.DependencyInjection;
namespace DevExpress.AspNetCore.Demos {
public class LargeDatabaseUnitOfWork : UnitOfWork {
public LargeDatabaseUnitOfWork(IDataLayer dataLayer)
: base(dataLayer) {
}
public XPQuery<XPEmail> Emails => this.Query<XPEmail>();
}
[Persistent("Emails")]
public class XPEmail : XPLiteObject {
public XPEmail(Session session)
: base(session) {
}
[Key(true)]
public int ID {
get => GetPropertyValue<int>("ID");
set => SetPropertyValue("ID", value);
}
[Size(100)]
public string Subject {
get => GetPropertyValue<string>("Subject");
set => SetPropertyValue("Subject", value);
}
[Size(32)]
public string From {
get => GetPropertyValue<string>("From");
set => SetPropertyValue("From", value);
}
}
public static class XpoServiceExtensions {
static readonly Type[] EntityTypes = new Type[] { typeof(XPEmail) };
static ReflectionDictionary ReflectionDictionary = new ReflectionDictionary();
static XpoServiceExtensions() {
ReflectionDictionary.GetDataStoreSchema(EntityTypes);
}
public static IServiceCollection AddLargeDatabaseUnitOfWork(this IServiceCollection services, string connectionString) {
services.AddSingleton<LargeDatabaseDataLayer>(serviceProvider => {
return CreatePooledDataLayer(connectionString);
});
services.AddScoped<LargeDatabaseUnitOfWork>(serviceProvider => {
var dataLayer = serviceProvider.GetService<LargeDatabaseDataLayer>();
return new LargeDatabaseUnitOfWork(dataLayer);
});
return services;
}
static LargeDatabaseDataLayer CreatePooledDataLayer(string connectionString) {
using(var updateDataLayer = XpoDefault.GetDataLayer(connectionString, ReflectionDictionary, AutoCreateOption.DatabaseAndSchema)) {
updateDataLayer.UpdateSchema(false, ReflectionDictionary.CollectClassInfos(EntityTypes));
}
var dataStore = XpoDefault.GetConnectionProvider(XpoDefault.GetConnectionPoolString(connectionString), AutoCreateOption.SchemaAlreadyExists);
return new LargeDatabaseDataLayer(ReflectionDictionary, dataStore);
}
}
public class LargeDatabaseDataLayer : ThreadSafeDataLayer {
public LargeDatabaseDataLayer(XPDictionary dictionary, IDataStore provider)
: base(dictionary, provider) {
}
}
}
See also the Binding to Large Database using XPO online demo and the Getting Started with .NET Core article.
See Also