Before you start, make sure you have the following installed:
-
DevExpress XAF (eXpressApp Framework) (25.1.x)
-
Devart Entity Developer (Edition for Entity Framework) (7.3.235)
There are two files:
.tmpl(T4 template file).xml(metadata)
Copy the two files into the folder located at:
C:\Program Files (x86)\Common Files\Devart\EntityDeveloper\Shared Templates
-
Create an app using the XAF wizard.
-
Save, close, and reopen the project.
-
Create a new Devart EF Core model file.
- Right-click > Add > New Item
- Choose:
DataorASP.NET Core > Data - Select: Devart EF Core Model
-
Select "Database First" approach.
-
Configure the SQL Server connection.
- Choose server and database.
- In Advanced, set the following:
MultipleActiveResultSets=True Encrypt=True TrustServerCertificate=True
-
Generate model from database.
- Select the desired tables or select them later.
-
Leave the default settings
-
Configure context and namespace:
- Namespace context/entities: <YourNameProject>.Module.BusinessObjects
- Context Class Name: <YourNameProject>EFCoreDbContext
-
Add the custom template:
- Click the first "Add Template" button
- From
Shared, choose: EF Core XAF - Remove any other existing template
-
Click "Finish" to complete the setup.
-
Change code in XAF wizard
//[TypesInfoInitializer(typeof(TelemacoContextInitializer))]
public partial class TelemacoEFCoreDbContext : DbContext {
//public TelemacoEFCoreDbContext(DbContextOptions<TelemacoEFCoreDbContext> options) : base(options) {
//}
//public DbSet<ModuleInfo> ModulesInfo { get; set; }
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
modelBuilder.UseDeferredDeletion(this);
modelBuilder.UseOptimisticLock();
modelBuilder.SetOneToManyAssociationDeleteBehavior(DeleteBehavior.SetNull, DeleteBehavior.Cascade);
modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues);
modelBuilder.UsePropertyAccessMode(PropertyAccessMode.PreferFieldDuringConstruction);
}
}Your Devart EF Core model will now generate code thatโs fully compatible with DevExpress XAF using the customized T4 template.