src/Misc/EFTools/EntityDesignDatabaseGeneration/EdmExtensions.cs
/// <summary>
///     Converts a string representation of conceptual schema definition language (CSDL) to an
///     <see
///         cref="EdmItemCollection" />
///     and validates it.
/// </summary>
/// <param name="csdl">Conceptual model metadata as a string.</param>
/// <param name="targetFrameworkVersion">The targeted version of the Entity Framework.</param>
/// <returns>
///     CSDL as an <see cref="EdmItemCollection" />.
/// </returns>
Converts a string representation of conceptual schema definition language (CSDL) to an

and validates it.
Converts a string representation of conceptual schema definition language ( CSDL ) to an and validates it .
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "csdl")]
        public static EdmItemCollection CreateAndValidateEdmItemCollection(string csdl, Version targetFrameworkVersion)
        {
            if (csdl == null)
            {
                throw new ArgumentNullException("csdl");
            }
            if (targetFrameworkVersion == null)
            {
                throw new ArgumentNullException("targetFrameworkVersion");
            }
            if (!EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion))
            {
                throw new ArgumentException(
                    string.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion),
                    "targetFrameworkVersion");
            }
            IList<EdmSchemaError> schemaErrors;
            EdmItemCollection edmItemCollection;
            using (var textReader = new StringReader(csdl))
            {
                using (var xmlReader = XmlReader.Create(textReader))
                {
                    edmItemCollection = EdmItemCollection.Create(new[] { xmlReader }, null, out schemaErrors);
                }
            }
            if (schemaErrors.Count > 0)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        Resources.ErrorCsdlNotValid,
                        string.Join(Environment.NewLine, schemaErrors.Select(e => e.Message))));
            }
            if (edmItemCollection.CsdlVersion() > targetFrameworkVersion)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        Resources.TargetVersionSchemaVersionMismatch,
                        edmItemCollection.CsdlVersion(),
                        targetFrameworkVersion));
            }
            return edmItemCollection;
        }
[ SuppressMessage ( " " , " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] public static EdmItemCollection CreateAndValidateEdmItemCollection ( string csdl , Version targetFrameworkVersion ) { if ( csdl == null ) { throw new ArgumentNullException ( " " ) ; } if ( targetFrameworkVersion == null ) { throw new ArgumentNullException ( " " ) ; } if ( ! EntityFrameworkVersion . IsValidVersion ( targetFrameworkVersion ) ) { throw new ArgumentException ( string . Format ( CultureInfo . CurrentCulture , Resources . ErrorNonValidTargetVersion , targetFrameworkVersion ) , " " ) ; } IList < EdmSchemaError > schemaErrors ; EdmItemCollection edmItemCollection ; using ( var textReader = new StringReader ( csdl ) ) { using ( var xmlReader = XmlReader . Create ( textReader ) ) { edmItemCollection = EdmItemCollection . Create ( new [ ] { xmlReader } , null , out schemaErrors ) ; } } if ( schemaErrors . Count > 0 ) { throw new InvalidOperationException ( String . Format ( CultureInfo . CurrentCulture , Resources . ErrorCsdlNotValid , string . Join ( Environment . NewLine , schemaErrors . Select ( e => e . Message ) ) ) ) ; } if ( edmItemCollection . CsdlVersion ( ) > targetFrameworkVersion ) { throw new InvalidOperationException ( String . Format ( CultureInfo . CurrentCulture , Resources . TargetVersionSchemaVersionMismatch , edmItemCollection . CsdlVersion ( ) , targetFrameworkVersion ) ) ; } return edmItemCollection ; }
Converts a string representation of conceptual schema definition language (CSDL) to an
Converts a string representation of conceptual schema definition language ( CSDL ) to an
CSDL as an .
CSDL as an .
csdl
string
Conceptual model metadata as a string.
Conceptual model metadata as a string .
targetFrameworkVersion
Version
The targeted version of the Entity Framework.
The targeted version of the Entity Framework .