wpf-devexpress-dot-xpf-dot-scheduling-dot-datasource-7c3e1fa7.md
Allows you to load appointments only for the specified date range.
Namespace : DevExpress.Xpf.Scheduling
Assembly : DevExpress.Xpf.Scheduling.v25.2.dll
NuGet Package : DevExpress.Wpf.Scheduling
public event FetchDataEventHandler FetchAppointments
Public Event FetchAppointments As FetchDataEventHandler
The FetchAppointments event's data class is FetchDataEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| AsyncResult | Gets or sets a task that allows you to fetch data asynchronously in the SchedulerControl. |
| CancellationToken | Gets an object that notifies that the current data load has been cancelled during the asynchronous data fetch. The CancellationToken property is used when the RefreshData() method is invoked. |
| Ids | Returns the identifiers of scheduler items that have been reloaded by the ReloadAppointments/ReloadTimeRegions methods. |
| Interval | Returns the time range for which to fetch the scheduler items. |
| Result | Specifies the list of scheduler items to load from the data source. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| GetFetchExpression<T>() | Generates an expression that you can use to obtain appointments from the data source. |
| IsVisibleInterval() | Determines whether a specified interval is visible in the SchedulerControl at the current moment during the asynchronous data load. |
Specify AppointmentMappings.QueryStart and AppointmentMappings.QueryEnd mappings to handle the FetchAppointments event.
These mappings allow you to calculate the correct interval that is used in a SELECT query when you handle the FetchAppointments event. The use of the AppointmentMappings.Start and AppointmentMappings.End properties is not recommended in this scenario because such an interval may not include appointment patterns and the corresponding appointment exceptions.
The example below illustrates how to fetch appointments from a DbContext source. The FetchMode property is set to Bound.
public class SchedulingDataContext : DbContext {
public SchedulingDataContext() : base(CreateConnection(), true) { }
static DbConnection CreateConnection() {
//...
}
public DbSet<AppointmentEntity> AppointmentEntities { get; set; }
//...
}
private void dataSource_FetchAppointments(object sender, DevExpress.Xpf.Scheduling.FetchDataEventArgs e) {
using (var dbContext = new SchedulingDataContext()) {
e.AsyncResult = dbContext.AppointmentEntities
.Where(x => x.QueryStart <= e.Interval.End
&& x.QueryEnd >= e.Interval.Start)
.ToArrayAsync();
}
}
Public Class SchedulingDataContext
Inherits DbContext
Public Sub New()
MyBase.New(CreateConnection(), True)
End Sub
Private Shared Function CreateConnection() As DbConnection
'...
End Function
Public Property AppointmentEntities() As DbSet(Of AppointmentEntity)
'...
End Class
Private Sub dataSource_FetchAppointments(ByVal sender As Object, ByVal e As DevExpress.Xpf.Scheduling.FetchDataEventArgs)
Using dbContext = New SchedulingDataContext()
Dim res = dbContext.AppointmentEntities.Where(args.GetFetchExpression(Of AppointmentEntity)())
args.AsyncResult = QueryableExtensions.ToArrayAsync(Of Object)(res)
End Using
End Sub
The FetchRange property specifies the time interval for which to fetch the appointments. FetchAppointments loads items for the SchedulerControl.VisibleIntervals extended up to the FetchRange.
Refer to this topic for more information: Load Data on Demand.
See Also