[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Collapse]Getting Started
   Tutorial 1 - Your First Data-Aware Application with XPO
   Tutorial 2 - Relations (One to Many)
   Tutorial 3 - Querying Data
   Tutorial 4 - A Windows Forms Application for Data Editing
   Tutorial 5 - An ASP .NET Application for Data Editing
   Tutorial 6 - A Simple Guestbook (ASP.NET)
   Getting Started with .NET Core
 [Expand]Fundamentals
 [Expand]Feature Center
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Examples
 [Expand]Member Tables
 [Expand]API Reference
[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)

Getting Started with .NET Core

This tutorial demonstrates how to create an XPO-based .NET Standard 2.0 console application that initializes the data layer and performs basic data operations.

Note

The complete sample project is available at https://github.com/DevExpress/XPO/tree/master/Tutorials/Console. You can also find examples of XPO-based ASP.NET Core and Xamarin.Forms applications in the DevExpress XPO for .NET Standard 2.0 Demos GitHub repository.

Expanded Prerequisites

.NET Core 2.0 SDK for Windows, Linux or Mac.

Expanded Create a Project

Open the system console and execute the following command to create a new C# project (you can substitute MyXpoApp with your project name):

To create a VB.NET project instead, add the '-lang vb' switch to the command.

Expanded Get XPO for .NET Core

Change the current directory to the project's directory.

Install the DevExpress.Xpo NuGet package.

Expanded Install the Database Provider

Install the Microsoft.Data.Sqlite package with the following command to use the local SQLite database:

You can use any other .NET Standard 2.0 compatible provider XPO supports (see Database Systems Supported by XPO).

Expanded Define the Data Model

In general, using XPO for .NET Core is the same as .NET Framework 3.5+. APIs, demonstrated in the XPO tutorials and Examples, are in the same namespaces (DevExpress.Xpo, DevExpress.Xpo.DB, etc.). You can use the same classes to define the data model and query data: XPObject, UnitOfWork, Session, XPCollection, etc.

Edit the MyXpoApp/Program.cs(vb) file (or add a new code file to the project) and implement the following StatisticInfo persistent class with the Key, Info and Date properties. The class is mapped to the StatisticInfo table with the Key, Info and Date columns.

Expanded Setup the Data Layer

In the Program.cs(vb) file, modify the Program.Main method. Pass the connection string to the XpoDefault.GetDataLayer method and assign the created IDataLayer object to the XpoDefault.DataLayer property.

Expanded Make CRUD Operations with Data

You can use the Unit of Work API to execute create, read, update and delete (CRUD) operations. For example, you can add the following code after the data layer initialization:

Save the changes in the Program.cs file. Now you can run the application using the dotnet run command in the system console.

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