-
Notifications
You must be signed in to change notification settings - Fork 227
Common Settings Types explained
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore8;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;
Settings.FileManagerType = FileManagerType.Custom;
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore7;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;
Settings.FileManagerType = FileManagerType.Custom;
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore6;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;
Settings.FileManagerType = FileManagerType.Custom;
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.Ef6;
Settings.GeneratorType = GeneratorType.Ef6;
Settings.UseMappingTables = true;
Settings.FileManagerType = FileManagerType.VisualStudio;
You can specify the database type here, which can be one of:
public enum DatabaseType
{
SqlServer,
SqlCe,
SQLite,
Plugin, // See Settings.DatabaseReaderPlugin
PostgreSQL,
MySql, // Not yet implemented
Oracle // Not yet implemented
}
It drives which database reader is created, and therefore what SQL is used to read the database schema information.
You can specify the mustache template type to use here, which can be one of:
public enum TemplateType
{
Ef6,
EfCore6,
EfCore7,
EfCore8,
FileBasedEf6,
FileBasedCore6,
FileBasedCore7,
FileBasedCore8
}
It drives which mustache template class is created, and therefore what mustache templates text is used to generate the code. The TemplateFactory.Create()
method is used to create the template.
public static class TemplateFactory
{
public static Template Create()
{
switch (Settings.TemplateType)
{
case TemplateType.Ef6:
return new TemplateEf6();
case TemplateType.EfCore6:
return new TemplateEfCore6();
case TemplateType.EfCore7:
return new TemplateEfCore7();
case TemplateType.EfCore8:
return new TemplateEfCore8();
case TemplateType.FileBasedEf6:
case TemplateType.FileBasedCore6:
case TemplateType.FileBasedCore7:
case TemplateType.FileBasedCore8:
return new TemplateFileBased();
default:
throw new ArgumentOutOfRangeException();
}
}
}
You could modify the mustache strings in TemplateEf6
, or TemplateEfCore
, however, these would be lost if you were to update the generator with a new version. You may be better off keeping your own mustache files in a folder within your project somewhere. In which case you can specify:
Settings.TemplateType = TemplateType.FileBased;
Settings.TemplateFolder = "c:\\path_to_your_templates";
Please read Custom file-based templates for more info.
You can specify the generator type here, which can be one of:
public enum GeneratorType
{
Ef6,
EfCore,
Custom
}
It drives which generator class is created and goes hand in hand with which template is used as it is responsible for creating the data the template will use to generate the output code.
- If TemplateType = Ef6, please use
GeneratorType.Ef6
- If TemplateType = EfCore2 or EfCore3, please use
GeneratorType.EfCore
- If TemplateType = FileBased, match whatever your template is trying to create:
GeneratorType.Ef6
,GeneratorType.EfCore
, orGeneratorType.Custom
. ForGeneratorType.Custom
, you will have to edit theGeneratorCustom
class and fill in your own code for setting up the column's entity and configuration. Take a look atGeneratorEf6
andGeneratorEfCore
to see what's been done for those.
You can specify the file manager type here, which can be one of:
public enum FileManagerType
{
// Use this for .NET 4.x projects.
// It will make use of the `EF6.Utility.CS.ttinclude` to add/remove files to the Visual Studio project.
VisualStudio,
// Use this for .NET Core projects.
// It will write the files directly.
// Visual Studio will automatically detect new files and include them in the project.
EfCore,
[Obsolete("Please use FileManagerType.EfCore instead")]
Custom,
Null // For testing only. Does nothing.
}
It drives which file manager is used to create the files.
-
FileManagerType.VisualStudio
. Use this for .NET 4.x projects. It will make use of theEF6.Utility.CS.ttinclude
to add/remove files from the Visual Studio project. -
FileManagerType.Custom
. Use this for .NET Core projects. It will write the files directly. Visual Studio will automatically detect new files and include them in the project. -
FileManagerType.Null
. This is used for testing, and won't generate any output.
If you delete tables from your database and you are using FileManagerType.Custom
, then you have to manually remove the generated classes yourself from your project as these will not be deleted.
It all boils down to how you want the generator to interact with Visual Studio.
It will make use of the EF6.Utility.CS.ttinclude
to add/remove files from the Visual Studio project. This is how version 2 of the generator worked. It instructs Visual Studio on which files to add/remove from the project. Visual Studio does not like this if you are using a .NET Core project as the files are not listed in the .csproj
file.
For example, the .csproj file would list your project files with Compile Includes
such as:
<ItemGroup>
<Compile Include="AssemblyHelper.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="OrderManagement\OrderValidator.cs" />
...
Use this for .NET Core projects. It will write the files directly to the file system, and not control Visual Studio at all. EF6.Utility.CS.ttinclude
is not used either. Visual Studio will automatically detect new files being present in the folder and include them in the project. The projects .csproj
does not include the files in the project. Visual Studio is basically working on a folder with a collection of files and sub-folders in it.
For example, the .csproj file would not list all the files in your project. It may list a few sub-folders, but not list any of the files in those either.
Use notepad and take a look at the .csproj
file. If it does not list all the files in your project, then use FileManagerType.Custom
, if it does then use FileManagerType.VisualStudio
.
Using FileManagerType.VisualStudio
on a project in Visual Studio where the project type does not list any files (.NET Core projects) confuses Visual Studio. The generator is telling Visual Studio to add/remove files from its project file, and no files are listed in the project file in the first place. In early versions of Visual Studio 2017/2019, this used to be a problem, however, this is no longer the case and now works ok.