src/Misc/EFTools/EntityDesign/VisualStudio/ModelWizard/DbContextCodeGenerator.cs
// <summary>
//     Adds the DbContext templates for the given EDMX project item if the templates are
//     installed and can be used, otherwise does nothing.
// </summary>
// <param name="edmxItem">The project item representing the EDMX model.</param>
// <param name="useLegacyTemplate">A value indicating whether to use the legacy version of the template.</param>
Adds the DbContext templates for the given EDMX project item if the templates are
installed and can be used, otherwise does nothing.
Adds the DbContext templates for the given EDMX project item if the templates are installed and can be used otherwise does nothing .
public void AddDbContextTemplates(ProjectItem edmxItem, bool useLegacyTemplate = true)
        {
            Debug.Assert(edmxItem != null, "edmxItem is null.");
            var templatePath = FindDbContextTemplate(edmxItem.ContainingProject, useLegacyTemplate);
            if (templatePath != null)
            {
                try
                {
                    var edmxFilePath = edmxItem.get_FileNames(1);
                    var edmxFileName = Path.GetFileNameWithoutExtension(edmxFilePath);
                    AddArtifactGeneratorWizard.EdmxUri = Utils.FileName2Uri(edmxFilePath);
                    if (!(edmxItem.ProjectItems ?? edmxItem.Collection).OfType<ProjectItem>().Any(
                        i => string.Equals(i.Name, edmxFileName + ".tt", StringComparison.OrdinalIgnoreCase)))
                    {
                        AddAndNestCodeGenTemplates(
                            edmxItem,
                            () => edmxItem.Collection.AddFromTemplate(templatePath, edmxFileName));
                    }
                }
                finally
                {
                    AddArtifactGeneratorWizard.EdmxUri = null;
                }
            }
        }
public void AddDbContextTemplates ( ProjectItem edmxItem , bool useLegacyTemplate = true ) { Debug . Assert ( edmxItem != null , " " ) ; var templatePath = FindDbContextTemplate ( edmxItem . ContainingProject , useLegacyTemplate ) ; if ( templatePath != null ) { try { var edmxFilePath = edmxItem . get_FileNames ( 1 ) ; var edmxFileName = Path . GetFileNameWithoutExtension ( edmxFilePath ) ; AddArtifactGeneratorWizard . EdmxUri = Utils . FileName2Uri ( edmxFilePath ) ; if ( ! ( edmxItem . ProjectItems ?? edmxItem . Collection ) . OfType < ProjectItem > ( ) . Any ( i => string . Equals ( i . Name , edmxFileName + " " , StringComparison . OrdinalIgnoreCase ) ) ) { AddAndNestCodeGenTemplates ( edmxItem , ( ) => edmxItem . Collection . AddFromTemplate ( templatePath , edmxFileName ) ) ; } } finally { AddArtifactGeneratorWizard . EdmxUri = null ; } } }
Adds the DbContext templates for the given EDMX project item if the templates are
installed and can be used, otherwise does nothing.
Adds the DbContext templates for the given EDMX project item if the templates are installed and can be used otherwise does nothing .
edmxItem
ProjectItem
The project item representing the EDMX model.
The project item representing the EDMX model .
useLegacyTemplate
bool
A value indicating whether to use the legacy version of the template.
A value indicating whether to use the legacy version of the template .