Skip to main content
.NET Standard 2.0+

How to: Apply Attributes to Entity Properties when Using Model First

  • 2 minutes to read

In a Model First data model, object properties are declared in the designer-generated files, and you cannot decorate them with the required built-in attributes directly. The workaround is to apply the MetadataType attribute to a class, create the metadata class, and apply the required attributes to the properties of the metadata. The code below illustrates this approach using the data model from the How to: Use the Entity Framework 6 Model First in XAF example.


ASP.NET Core Blazor applications do not support the EF 6 business model.


A complete sample project is available in the DevExpress Code Examples database at

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using DevExpress.ExpressApp.DC;
// ...
public partial class Employee {
public class EmployeeMetadata {
    public Int32 Id { get; set; }
public partial class Task {
public class TaskMetadata {
    public Int32 Id { get; set; }
    public String Description { get; set; }

A reference to System.ComponentModel.DataAnnotations is required to compile the code above. Here, we use the Browsable attribute to hide the Id properties (which are key properties in our data model) from the UI. The FieldSizeAttribute specifies that an unlimited number of characters can be stored in the Task.Description property, so a multiline editor will be used for this property in the UI.

See Also