src/Misc/EntityFramework.PowerShell/ConnectionFactoryConfig/ConfigFileManipulator.cs
// <summary>
// Sets the EntityFramework "defaultConnectionFactory" in the given XML document representing a
// .config file to use th given specification. This method differs from AddConnectionFactoryToConfig
// in that it always sets the entry to use the given specification even if it was already present
// and set to something else.
// </summary>
// <param name="config"> An XML document representing the config file. </param>
// <param name="specification"> Specifies the connection factory and constructor arguments to use. </param>
// <returns> True if the document was modified; false if no change was made. </returns>
Sets the EntityFramework "defaultConnectionFactory" in the given XML document representing a
.config file to use th given specification. This method differs from AddConnectionFactoryToConfig
in that it always sets the entry to use the given specification even if it was already present
and set to something else.
Sets the EntityFramework " defaultConnectionFactory " in the given XML document representing a . config file to use th given specification . This method differs from AddConnectionFactoryToConfig in that it always sets the entry to use the given specification even if it was already present and set to something else .
public virtual bool AddOrUpdateConnectionFactoryInConfig(XDocument config, ConnectionFactorySpecification specification)
        {
            DebugCheck.NotNull(config);
            var connectionFactoryElement = config
                .GetOrCreateElement(ConfigurationElementName)
                .GetOrCreateElement(EntityFrameworkElementName)
                .GetOrCreateElement(DefaultConnectionFactoryElementName);
            var currentFactoryAttribute = connectionFactoryElement.Attribute("type");
            if (currentFactoryAttribute != null
                && specification.ConnectionFactoryName.Equals(currentFactoryAttribute.Value, StringComparison.OrdinalIgnoreCase)
                && FactoryArgumentsMatch(connectionFactoryElement, specification))
            {
                return false;
            }
            connectionFactoryElement.RemoveAll();
            connectionFactoryElement.Add(new XAttribute("type", specification.ConnectionFactoryName));
            AddFactoryArguments(connectionFactoryElement, specification);
            return true;
        }
public virtual bool AddOrUpdateConnectionFactoryInConfig ( XDocument config , ConnectionFactorySpecification specification ) { DebugCheck . NotNull ( config ) ; var connectionFactoryElement = config . GetOrCreateElement ( ConfigurationElementName ) . GetOrCreateElement ( EntityFrameworkElementName ) . GetOrCreateElement ( DefaultConnectionFactoryElementName ) ; var currentFactoryAttribute = connectionFactoryElement . Attribute ( " " ) ; if ( currentFactoryAttribute != null && specification . ConnectionFactoryName . Equals ( currentFactoryAttribute . Value , StringComparison . OrdinalIgnoreCase ) && FactoryArgumentsMatch ( connectionFactoryElement , specification ) ) { return false ; } connectionFactoryElement . RemoveAll ( ) ; connectionFactoryElement . Add ( new XAttribute ( " " , specification . ConnectionFactoryName ) ) ; AddFactoryArguments ( connectionFactoryElement , specification ) ; return true ; }
Sets the EntityFramework "defaultConnectionFactory" in the given XML document representing a
.config file to use th given specification.
Sets the EntityFramework " defaultConnectionFactory " in the given XML document representing a . config file to use th given specification .
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 .
specification
ConnectionFactorySpecification
Specifies the connection factory and constructor arguments to use.
Specifies the connection factory and constructor arguments to use .