[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Collapse]Scheduler
   [Expand]Getting Started
   [Expand]Appointments
    Resources
    Reminders
   [Expand]Views
   [Expand]Visual Elements
   [Expand]Styles and Templates
   [Expand]Design-Time Features
    Time Zones
   [Expand]Data Binding
    Grouping
    Selecting
    Navigating
    Printing
    End-User Restrictions
   [Collapse]Examples
    [Expand]How to: Create Recurrence in Code
     How to: Display the Integrated Ribbon for the Scheduler
     How to: Create the Scheduler with the DateNavigator
     How to: Bind Scheduler to Data using the Entity Framework Code First Approach
     How to: Customize Editing and Recurrence Dialogs
     How to: Customize the In-Place Editor
     How to: Create Custom Labels and Statuses
     How to: Customize Appointment Appearance
     How to: Determine what Scheduler Element Is Hovered by the Mouse Pointer
     How to: Set Default Values for a New Appointment
     How to: Print a Scheduler Using Reports from a Document Preview Window
    Migration Guidelines
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Bind Scheduler to Data using the Entity Framework Code First Approach

This example describes how to bind the Scheduler to a data source using the Entity Framework Code First approach.

Perform the following steps to achieve the required result:

Expanded Create New Scheduling Application

  1. Create a new WPF Application project and open the MainWindow.xaml file in the Visual Studio Designer.
  2. Add the SchedulerControl object to your project. You can do this by dragging the SchedulerControl item from the DX.18.2: Scheduling Toolbox tab to the canvas.

  3. Right-click the SchedulerControl object and select Layout | Reset All in the context menu to stretch the SchedulerControl so that it fills the entire window.

Expanded Create a Data Model

Note

Before creating a Data Model, make sure that the Entity Framework package is added to your Visual Studio. Refer to the Get Entity Framework article for details on how to install the Entity Framework package.

  1. Right-click on the project name. Select Add | New Item.
  2. Select Data | ADO .NET Entity Data Model and enter MySchedulerModel for the name.
  3. In the Entity Data Model Wizard, select Code First from database to generate an EF model based on your database.

    Click Next and select the database to be used (in this example, we use CarsDB.mdf data source). Then select the desired tables and click Finish.

    As a result, new classes are added to your solution. The MySchedulerModel class is the DBContext class descendant which allows you to query and save entity class instances. Other classes represent individual database tables.

Expanded Create a ViewModel

Add a new folder to your project. Right-click the project's name in the Solution Explorer, and then select Add | New Folder. Change the folder name to ViewModel.

Add a MainViewModel class. In the Solution Explorer, right-click the ViewModel folder, and then select Add | Class…. In the invoked Add New Item window, assign the MainViewModel name to the class.

Add the following code to handle data interaction:

  1. Apply the POCOViewModel attribute to your View Model. Refer to the POCO ViewModel topic for details;
  2. The Data Model created in previous section (the MySchedulerModel class instance) is the data source to fill two ObservableCollection type collections which are used for data binding;

  3. Declare a method that implements the AppointmentsUpdatedCommand. In the method body, call the MySchedulerModel instance's SaveChanges method to save newly created appointments;

  4. Create a method for the InitNewAppointmentCommand, as shown in the code example below:

  5. Fill the Appointments and Resources collection with data using the Load method.

Expanded Set Mapping and Binding in XAML

  1. Use the ViewModelSource to set the DataContext property to the ViewModel as follows:

  2. Use the EventToCommand behaviors to bind the AppointmentUpdated and InitNewAppointment events to the related commands:

  3. Set the required mappings as shown in the code snippet below:

Expanded Run the Application

The following image demonstrates the result:

Is this topic helpful?​​​​​​​