Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]ASP.NET WebForms Controls
 [Collapse]ASP.NET MVC Extensions
  [Expand]Product Information
  [Expand]Getting Started
  [Expand]Common Concepts
  [Expand]Grid View
  [Collapse]Card View
    Overview - CardView
    Main Features - Card View
   [Collapse]Concepts
    [Collapse]Binding to Data
      Binding to Data via Entity Framework (Code First)
      Binding to Data via Entity Framework or LINQ to SQL (Database First)
      Binding to Large Data (Database Server Mode)
     [Expand]Custom Data Binding
    [Expand]Data Representation Basics
    [Expand]Focus and Navigation
    [Expand]Data Editing and Validation
  [Expand]Vertical Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]HTML Editor
  [Expand]Image and Data Browsing
  [Expand]Docking and Popups
  [Expand]Navigation and Layout Extensions
  [Expand]File Management
  [Expand]Multi-Use Site Extensions
  [Expand]Charts
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Tree List
  [Expand]Data Editor Extensions
  [Expand]Report Extensions
  [Expand]SpellChecker
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Binding to Data via Entity Framework or LINQ to SQL (Database First)

The DevExpress MVC CardView supports binding to an existing data source using LINQ or the Entity Framework.

If you already have a database, the LINQ to SQL ORM Framework or the Entity Framework ORM can automatically generate a data model that consists of classes and properties that correspond to existing database objects such as tables and columns. This development approach is called "Database First".

This topic describes how to bind the MVC CardView to a data source using the "Database First" development approach.

Important

Project requirements:

Your project should be prepared for using DevExpress MVC Extensions. See the following topic to learn how to prepare your project: Integration into an ASP.NET MVC Project.

To use the Server Mode with Entity Framework 6+, it is necessary to use special options on the application startup. To learn more, see the Knowledge Base Article: Is it possible to use the Entity Framework 6 and Server Mode together.

To implement this kind of data binding, you need to perform the following steps.

Expanded Step 1. Create a data model

Use the required ORM framework to reverse engineer a model from an existing database.

  • LINQ to SQL ORM Framework

    Create a LINQ to SQL data model. The following MSDN topic demonstrates how to add LINQ to SQL data model classes using the O/R designer: How to: Add LINQ to SQL Classes to a Project (O/R Designer).

    Refer to the following MSDN Learning Center article to learn more about the LINQ to SQL ORM Framework: LINQ to SQL.

  • Entity Framework ORM

    Note

    Before you start, make sure you have the Entity Framework installed. Learn more about how to get the Entity Framework from the following MSDN tutorial: Get Entity Framework.

    Create an Entity Framework data model. The following walkthrough demonstrates how to reverse engineer a model from an existing database: Entity Framework Database First.

 

Rebuild the solution before going on to the next step.

Expanded Step 2. Add the CardView to the required View

Open the required View file (Index.cshtml in this topic), focus on the position in the code where you would like to insert the CardView, right-click and select "Insert DevExpress MVC Extension v17.1"

The Insert Extension Wizard opens. Navigate to the tab with the Data extensions and select the CardView. Define the extension name and the partial view name. In the 'Model class' item, select the data model class; in the 'Data context class' item, select the data context class. Select the columns you wish to display within the CardView and select the key field.

Click the 'Insert' button, and the CardView will be added into your project. See this topic to learn more about the MVC Wizard: Insert DevExpress MVC Extension Wizard.

After performing these operations, Insert Extension Wizard generates a partial view that contains the CardView's settings and inserts the necessary code into the corresponding controller class. As a result, you have a fully functional MVC CardView bound to an existing data source.

Expanded See Also

How would you rate this topic?​​​​​​​