Log In
[Expand]Welcome to DevExpress .NET Documentation
[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]Document Server
[Expand]Report Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
  [Expand]Application Solution Components
  [Collapse]Business Model Design
    Business Model Design Basics
    Built-in Business Classes for Most Popular Scenarios
   [Expand]Business Model Design with Entity Framework
   [Expand]Business Model Design with XPO
    Non-Persistent Objects
    PropertyChanged Event in Business Classes
   [Collapse]Data Types Supported by built-in Editors
     Key Properties
    [Expand]String Properties
    [Expand]Numeric Properties
    [Expand]Date and Time Properties
    [Expand]Boolean Properties
    [Expand]BLOB Image Properties
    [Expand]Collection Properties
    [Expand]Reference (Foreign Key, Complex Type) Properties
    [Expand]File Attachment Properties
    [Expand]Type Properties
    [Expand]Enumeration Properties
    [Expand]Criteria Properties
    [Expand]Color Properties
     Geolocation Properties
     Miscellaneous Property Types
    Mapping Complex Types to the Database
   [Expand]Types Info Subsystem
    Connect an XAF Application to a Database Provider
    Data Annotations in Data Model
    Create and Update the Application's Database
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Extend Functionality
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]System Module
  [Expand]Extra Modules
  [Expand]Debugging, Testing and Error Handling
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Key Properties

One of the XAF's functions is managing a database via an ORM tool. Dealing with the database assumes that each object has a property that allows you to distinguish an object among other objects of the same type. In relational databases, such property is called a Unique key (primary key or simply a key). Each business class you create with an ORM tool must have a key property that will be used as a database unique key. Key property implementation differs, depending on the specific data access technology you use.

Expanded Entity Framework (EF)

When using EF, you can implement a key property by one of the following ways.

  • Implement a property named "Id"
  • Implement a property that combines the class name and "Id", such as "ContactId" (assuming that your class name is "Contact")
  • Decorate any property with the Key Attribute
For detailed information, refer to the Code First Data Annotations MSDN article.

The DataView mode does not support business objects with composite keys in EF.

Expanded eXpress Persistent Objects (XPO)

In most XPO cases, you needn't be concerned with the key property, because usually it is already implemented in a class that is used as the base for your own XPO business class. Refer to the Base Persistent Classes article for more information about different base classes to inherit from and their key properties.

If you need to implement your own key property, inherit your new class from one of the Base Persistent Classes without a key (XPLiteObject, XPBaseObject or XPCustomObject), implement a key property manually, then decorate it with the KeyAttribute.


We do not recommend implementing composite or compound keys for new databases. While it is possible to design persistent classes for legacy databases with composite keys in certain scenarios, it is always better to modify the database schema to avoid this as using composite keys imposes some limitations on the default functionality. Refer to the How to create a persistent object for a database table with a compound key KB article to learn more. If you use compound keys in an ASP.NET application, decorate the struct key property with the TypeConverterAttribute as described in the StructTypeConverter<T> article.

Domain Components (DC)

By default, DC uses key properties of the GUID type that are automatically inherited from the default base class — DCBaseObject. To change the default behavior, register your domain component using the "void ITypesInfo.RegisterEntity(string name, Type interfaceType, Type baseClass)" overload.

Expanded See Also

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