Skip to main content
.NET Standard 2.0+

Model First Specifics

  • 2 minutes to read

This topic lists the specifics of using the Entity Framework 6 data model created within the Entity Framework Designer (the Model First approach) in XAF. If you create your entities in code (Code First), skip this topic.

  1. In the Model First approach, a constructor with the connectionString parameter is required in the DbContext descendant when you specify the connection via the XafApplication.ConnectionString property or via the ConnectionString attribute in the configuration file (see Use the Entity Framework 6 Data Model). Add this constructor by creating a partial class that supplements your DbContext/ObjectContext descendant.

    public partial class MySolutionModelContainer : DbContext {
        public MySolutionModelContainer(string connectionString) : base(connectionString) { }
  2. When using Model First, the metadata part of the connection string specified in the configuration file (or directly assigned to XafApplication.ConnectionString) is required. You can copy the connection string from the App.Config file generated by the Entity Framework Designer.
  3. To be able to apply attributes to entity classes, add partial classes that supplement the designer-generated code. To apply attributes to entity properties, use the approach described in the How to: Apply Attributes to Entity Properties when Using Model First topic.
See Also