Closed Illinariss closed 4 years ago
@Illinariss Response to Question 1:
Is there a way to run Scaffolding once and generate entities for more than one project at the same time? [paraphrased]
Not really. The way the EF Core CLI works is that it is scoped to just one project, called the "startup project," which must be a .NET Core library or app. You can specify a different "target project," which can be for example a .NET Standard library, but you can only scaffold one project each time you run the dotnet ef dbcontext scaffold
command.
What you're going to need to do is run the scaffolding command twice: once for the client project and again for the server project. Each project will need its own CodeTemplates folder where you can customize the code generation in different ways.
@Illinariss Response to Question 2:
What is the right way to get the property informations?
You have the right approach. Extend HbsCSharpEntityTypeGenerator
to override GenerateProperties
, and extend HbsEntityTypeTransformationService
to override TransformProperties
.
Then add these lines of code to your ScaffoldingDesignTimeServices
class:
services.AddSingleton<ICSharpEntityTypeGenerator, MyHbsCSharpEntityTypeGenerator>();
services.AddSingleton<IEntityTypeTransformationService, MyHbsEntityTypeTransformationService>();
Note that using Handlebars templates is a different approach than T4 templates, where you can add imperative code to the template. With the Handlebars approach, imperative code is added by extending the base classes, which in the end, provides more flexibility and avoids what can become spaghetti code in your templates.
Alternatively, if you think property.IsKey
and property.IsForeignKey
might be useful for others, you can submit a pull request to add these, as well as other common property info properties. If so, be sure to read the project Contributing Guidelines first.
Please re-open if I can further clarify or answer any other questions.
Hi, two questions.
Question 1. I have 2 librarys for entities (client and server) and each needs different templates. At the moment I have to Switch the Templates for each Scaffolding. Is there a way to run Scaffolding once and:
Question 2. To get the
property.IsKey()
andproperty.IsForeignKey()
value i had to extentHbsCSharpEntityTypeGenerator
andHbsEntityTypeTransformationService
.What is the right way to get the property informations ?