EFCore 5 reverse engineering resulting in broken using statements for some models
See original GitHub issueOur generated models are now showing unnecessary (and invalid) using statements after running through the Reverse engineering process.
This is not occurring for all of the generated models; there is no clear pattern for which ones are affected by this and which ones are not.
The exact reproduction steps are listed below. I would like to call out that not checking the Customize code using Handlebars templates
does not produce the unnecessary and broken using
statements.
Our Handlebars templates have not changed since 2020, but for completeness I will include them below:
CodeTemplates/CSharpEntityType/Class.hbs
{{> imports}}
namespace {{namespace}}
{
{{#if comment}}
/// <summary>
/// {{comment}}
/// </summary>
{{/if}}
{{#each class-annotations}}
{{{class-annotation}}}
{{/each}}
public partial class {{class}}
{
{{{> constructor}}}
{{{> properties}}}
}
}
and
CodeTemplates/CSharpEntityType/Partials/Imports.hbs
using System;
using System.Collections.Generic;
{{#if use-data-annotations}}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
{{/if}}
{{#each imports}}
using {{import}};
{{/each}}
Steps to reproduce
No changes were introduced to our Azure MS SQL database. We go through the Reverse Engineering steps as follows:
- No filter schemas
- EF Core 5 selected
- Variety of tables are chosen for Database Objects.
- Context name, namespace, entity types path, dbContext path are given.
- Use table and column names directly from the database is checked.
- Customize code using Handlebars templates for C# is checked (we believe this to be part of the problem)
- Split DbContext into Configuration classes is checked.
- No other options are checked, we generate our models.
Screenshots of the exact settings below, if that is more useful:
Further technical details
EF Core Power Tools version: 2.5.758.0
Database engine: Azure SQL
Visual Studio version: Microsoft Visual Stuio Community 2019: Version 16.11.2
dotnet SDK version: 5.0.400
Issue Analytics
- State:
- Created 2 years ago
- Comments:37 (18 by maintainers)
Top GitHub Comments
Hi @ErikEJ 👋
I can confirm everything is looking correct w/ the latest daily. No unexpected
using
statements. Thanks a bunch for your help in resolving this.I think I need a repro database schema so I can investigate locally.
Creation of CodeTemplates folder should be automatic, I will investigate why you are getting errors.