src/Misc/EntityFramework.PowerShell/ConnectionFactoryConfig/ConfigFileManipulator.cs
// <summary>
// Ensures that the config file has a defined "entityFramework" section and that it references
// the current version of the Z.EntityFramework.Classic.dll assembly.
// </summary>
// <param name="config"> An XML document representing the config file. </param>
// <param name="entityFrameworkVersion"> The version of Z.EntityFramework.Classic.dll to use. </param>
// <returns> True if the document was modified; false if no change was made. </returns>
Ensures that the config file has a defined "entityFramework" section and that it references
the current version of the Z.EntityFramework.Classic.dll assembly.
Ensures that the config file has a defined " entityFramework " section and that it references the current version of the Z . EntityFramework . Classic . dll assembly .
public virtual bool AddOrUpdateConfigSection(XDocument config, Version entityFrameworkVersion)
        {
            DebugCheck.NotNull(config);
            DebugCheck.NotNull(entityFrameworkVersion);
            var configSections = config
                .GetOrCreateElement(ConfigurationElementName)
                .GetOrCreateElement(ConfigSectionsElementName);
            var typeAttribute = configSections
                .Elements(SectionElementName)
                .Where(e => (string)e.Attribute("name") == EntityFrameworkElementName)
                .SelectMany(e => e.Attributes("type"))
                .FirstOrDefault();
            const string entityFrameworkSectionName =
                "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, Z.EntityFramework.Classic, Version={0}, Culture=neutral, PublicKeyToken=afc61983f100d280";
            var efSectionTypeName = string.Format(
                CultureInfo.InvariantCulture, entityFrameworkSectionName,
                entityFrameworkVersion);
            if (typeAttribute != null)
            {
                var sectionElement = typeAttribute.Parent;
                var requirePermissionAttribute = sectionElement.Attribute("requirePermission");
                if (efSectionTypeName.Equals(typeAttribute.Value, StringComparison.InvariantCultureIgnoreCase)
                    && requirePermissionAttribute != null)
                {
                    return false;
                }
                typeAttribute.Value = efSectionTypeName;
                if (requirePermissionAttribute == null)
                {
                    sectionElement.Add(new XAttribute("requirePermission", false));
                }
            }
            else
            {
                configSections.Add(
                    new XElement(
                        SectionElementName, new XAttribute("name", EntityFrameworkElementName),
                        new XAttribute("type", efSectionTypeName), new XAttribute("requirePermission", false)));
            }
            return true;
        }
public virtual bool AddOrUpdateConfigSection ( XDocument config , Version entityFrameworkVersion ) { DebugCheck . NotNull ( config ) ; DebugCheck . NotNull ( entityFrameworkVersion ) ; var configSections = config . GetOrCreateElement ( ConfigurationElementName ) . GetOrCreateElement ( ConfigSectionsElementName ) ; var typeAttribute = configSections . Elements ( SectionElementName ) . Where ( e => ( string ) e . Attribute ( " " ) == EntityFrameworkElementName ) . SelectMany ( e => e . Attributes ( " " ) ) . FirstOrDefault ( ) ; const string entityFrameworkSectionName = " " ; var efSectionTypeName = string . Format ( CultureInfo . InvariantCulture , entityFrameworkSectionName , entityFrameworkVersion ) ; if ( typeAttribute != null ) { var sectionElement = typeAttribute . Parent ; var requirePermissionAttribute = sectionElement . Attribute ( " " ) ; if ( efSectionTypeName . Equals ( typeAttribute . Value , StringComparison . InvariantCultureIgnoreCase ) && requirePermissionAttribute != null ) { return false ; } typeAttribute . Value = efSectionTypeName ; if ( requirePermissionAttribute == null ) { sectionElement . Add ( new XAttribute ( " " , false ) ) ; } } else { configSections . Add ( new XElement ( SectionElementName , new XAttribute ( " " , EntityFrameworkElementName ) , new XAttribute ( " " , efSectionTypeName ) , new XAttribute ( " " , false ) ) ) ; } return true ; }
Ensures that the config file has a defined "entityFramework" section and that it references
the current version of the Z.EntityFramework.Classic.dll assembly.
Ensures that the config file has a defined " entityFramework " section and that it references the current version of the Z . EntityFramework . Classic . dll assembly .
// Hard coding this so that we don't need to load Z.EntityFramework.Classic.dll to get it.
True if the document was modified; false if no change was made.
True if the document was modified ; false if no change was made .
config
XDocument
An XML document representing the config file.
An XML document representing the config file .
entityFrameworkVersion
Version
The version of Z.EntityFramework.Classic.dll to use.
The version of Z . EntityFramework . Classic . dll to use .