Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.StoreItemCollection" /> class using the specified file paths.
        /// </summary>
        /// <param name="filePaths">The file paths used to create metadata.</param>
        public StoreItemCollection(params string[] filePaths)
            : base(DataSpace.SSpace)
        {
            Check.NotNull <string[]>(filePaths, nameof(filePaths));
            IEnumerable <string> enumerableArgument1 = (IEnumerable <string>)filePaths;

            EntityUtil.CheckArgumentEmpty <string>(ref enumerableArgument1, new Func <string, string>(Strings.StoreItemCollectionMustHaveOneArtifact), nameof(filePaths));
            List <XmlReader> source = (List <XmlReader>)null;

            try
            {
                MetadataArtifactLoader compositeFromFilePaths = MetadataArtifactLoader.CreateCompositeFromFilePaths(enumerableArgument1, ".ssdl");
                source = compositeFromFilePaths.CreateReaders(DataSpace.SSpace);
                IEnumerable <XmlReader> enumerableArgument2 = source.AsEnumerable <XmlReader>();
                EntityUtil.CheckArgumentEmpty <XmlReader>(ref enumerableArgument2, new Func <string, string>(Strings.StoreItemCollectionMustHaveOneArtifact), nameof(filePaths));
                this.Init((IEnumerable <XmlReader>)source, (IEnumerable <string>)compositeFromFilePaths.GetPaths(DataSpace.SSpace), true, (IDbDependencyResolver)null, out this._providerManifest, out this._providerFactory, out this._providerInvariantName, out this._providerManifestToken, out this._cachedCTypeFunction);
            }
            finally
            {
                if (source != null)
                {
                    Helper.DisposeXmlReaders((IEnumerable <XmlReader>)source);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.StoreItemCollection" /> class using the specified XMLReader.
        /// </summary>
        /// <param name="xmlReaders">The XMLReader used to create metadata.</param>
        public StoreItemCollection(IEnumerable <XmlReader> xmlReaders)
            : base(DataSpace.SSpace)
        {
            Check.NotNull <IEnumerable <XmlReader> >(xmlReaders, nameof(xmlReaders));
            EntityUtil.CheckArgumentEmpty <XmlReader>(ref xmlReaders, new Func <string, string>(Strings.StoreItemCollectionMustHaveOneArtifact), "xmlReader");
            MetadataArtifactLoader compositeFromXmlReaders = MetadataArtifactLoader.CreateCompositeFromXmlReaders(xmlReaders);

            this.Init((IEnumerable <XmlReader>)compositeFromXmlReaders.GetReaders(), (IEnumerable <string>)compositeFromXmlReaders.GetPaths(), true, (IDbDependencyResolver)null, out this._providerManifest, out this._providerFactory, out this._providerInvariantName, out this._providerManifestToken, out this._cachedCTypeFunction);
        }
        /// <summary>
        /// constructor that loads the metadata files from the specified xmlReaders, and returns the list of errors
        /// encountered during load as the out parameter errors.
        ///
        /// Publicly available from System.Data.Entity.Desgin.dll
        /// </summary>
        /// <param name="xmlReaders">xmlReaders where the CDM schemas are loaded</param>
        /// <param name="filePaths">the paths where the files can be found that match the xml readers collection</param>
        internal StoreItemCollection(IEnumerable <XmlReader> xmlReaders,
                                     IEnumerable <string> filePaths)
            : base(DataSpace.SSpace)
        {
            EntityUtil.CheckArgumentNull(filePaths, "filePaths");
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReader");

            this.Init(xmlReaders, filePaths, true,
                      out _providerManifest,
                      out _providerFactory,
                      out _providerManifestToken,
                      out _cachedCTypeFunction);
        }
Beispiel #4
0
 /// <summary>
 /// Configures the primary key property(s) for this entity type.
 /// </summary>
 /// <param name="keyProperties"> The properties to be used as the primary key. </param>
 /// <returns>
 /// The same <see cref="T:System.Data.Entity.ModelConfiguration.Configuration.ConventionTypeConfiguration" /> instance so that multiple calls can be chained.
 /// </returns>
 /// <remarks>
 /// Calling this will have no effect once it has been configured or if any
 /// property does not exist.
 /// </remarks>
 public ConventionTypeConfiguration HasKey(
     IEnumerable <PropertyInfo> keyProperties)
 {
     Check.NotNull <IEnumerable <PropertyInfo> >(keyProperties, nameof(keyProperties));
     EntityUtil.CheckArgumentContainsNull <PropertyInfo>(ref keyProperties, nameof(keyProperties));
     EntityUtil.CheckArgumentEmpty <PropertyInfo>(ref keyProperties, (Func <string, string>)(p => Strings.CollectionEmpty((object)p, (object)nameof(HasKey))), nameof(keyProperties));
     this.ValidateConfiguration(ConventionTypeConfiguration.ConfigurationAspect.HasKey);
     if (this._entityTypeConfiguration != null && !this._entityTypeConfiguration().IsKeyConfigured)
     {
         this._entityTypeConfiguration().Key(keyProperties);
     }
     return(this);
 }
Beispiel #5
0
        /// <summary>
        /// Factory method that creates a <see cref="StoreItemCollection" />.
        /// </summary>
        /// <param name="xmlReaders">
        /// SSDL artifacts to load. Must not be <c>null</c>.
        /// </param>
        /// <param name="filePaths">
        /// Paths to SSDL artifacts. Used in error messages. Can be <c>null</c> in which case
        /// the base Uri of the XmlReader will be used as a path.
        /// </param>
        /// <param name="resolver">
        /// Custom resolver. Currently used to resolve DbProviderServices implementation. If <c>null</c>
        /// the default resolver will be used.
        /// </param>
        /// <param name="errors">
        /// The collection of errors encountered while loading.
        /// </param>
        /// <returns>
        /// <see cref="StoreItemCollection" /> instance if no errors encountered. Otherwise <c>null</c>.
        /// </returns>
        public static StoreItemCollection Create(
            IEnumerable <XmlReader> xmlReaders,
            ReadOnlyCollection <string> filePaths,
            IDbDependencyResolver resolver,
            out IList <EdmSchemaError> errors)
        {
            Check.NotNull(xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentContainsNull(ref xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReaders");

            var storeItemCollection = new StoreItemCollection(xmlReaders, filePaths, resolver, out errors);

            return(errors != null && errors.Count > 0 ? null : storeItemCollection);
        }
        /// <summary>
        /// Public constructor that loads the metadata files from the specified xmlReaders.
        /// Throws when encounter errors.
        /// </summary>
        /// <param name="xmlReaders">xmlReaders where the CDM schemas are loaded</param>
        public StoreItemCollection(IEnumerable <XmlReader> xmlReaders)
            : base(DataSpace.SSpace)
        {
            EntityUtil.CheckArgumentNull(xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReader");

            MetadataArtifactLoader composite = MetadataArtifactLoader.CreateCompositeFromXmlReaders(xmlReaders);

            this.Init(composite.GetReaders(),
                      composite.GetPaths(), true,
                      out _providerManifest,
                      out _providerFactory,
                      out _providerManifestToken,
                      out _cachedCTypeFunction);
        }
Beispiel #7
0
        // <summary>
        // constructor that loads the metadata files from the specified xmlReaders, and returns the list of errors
        // encountered during load as the out parameter errors.
        // </summary>
        // <param name="xmlReaders"> xmlReaders where the CDM schemas are loaded </param>
        // <param name="filePaths"> the paths where the files can be found that match the xml readers collection </param>
        internal StoreItemCollection(
            IEnumerable <XmlReader> xmlReaders,
            IEnumerable <string> filePaths)
            : base(DataSpace.SSpace)
        {
            DebugCheck.NotNull(filePaths);
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReader");

            Init(
                xmlReaders, filePaths, /* throwOnError */ true, /* resolver */ null,
                out _providerManifest,
                out _providerFactory,
                out _providerInvariantName,
                out _providerManifestToken,
                out _cachedCTypeFunction);
        }
Beispiel #8
0
        /// <summary>
        /// Factory method that creates a <see cref="T:System.Data.Entity.Core.Metadata.Edm.StoreItemCollection" />.
        /// </summary>
        /// <param name="xmlReaders">
        /// SSDL artifacts to load. Must not be <c>null</c>.
        /// </param>
        /// <param name="filePaths">
        /// Paths to SSDL artifacts. Used in error messages. Can be <c>null</c> in which case
        /// the base Uri of the XmlReader will be used as a path.
        /// </param>
        /// <param name="resolver">
        /// Custom resolver. Currently used to resolve DbProviderServices implementation. If <c>null</c>
        /// the default resolver will be used.
        /// </param>
        /// <param name="errors">
        /// The collection of errors encountered while loading.
        /// </param>
        /// <returns>
        /// <see cref="T:System.Data.Entity.Core.Metadata.Edm.StoreItemCollection" /> instance if no errors encountered. Otherwise <c>null</c>.
        /// </returns>
        public static StoreItemCollection Create(
            IEnumerable <XmlReader> xmlReaders,
            ReadOnlyCollection <string> filePaths,
            IDbDependencyResolver resolver,
            out IList <EdmSchemaError> errors)
        {
            Check.NotNull <IEnumerable <XmlReader> >(xmlReaders, nameof(xmlReaders));
            EntityUtil.CheckArgumentContainsNull <XmlReader>(ref xmlReaders, nameof(xmlReaders));
            EntityUtil.CheckArgumentEmpty <XmlReader>(ref xmlReaders, new Func <string, string>(Strings.StoreItemCollectionMustHaveOneArtifact), nameof(xmlReaders));
            StoreItemCollection storeItemCollection = new StoreItemCollection(xmlReaders, filePaths, resolver, out errors);

            if (errors == null || errors.Count <= 0)
            {
                return(storeItemCollection);
            }
            return((StoreItemCollection)null);
        }
        /// <summary>
        /// Configures the primary key property(s) for this entity type.
        /// </summary>
        /// <param name="keyProperties"> The properties to be used as the primary key. </param>
        /// <returns>
        /// The same <see cref="ConventionTypeConfiguration" /> instance so that multiple calls can be chained.
        /// </returns>
        /// <remarks>
        /// Calling this will have no effect once it has been configured or if any
        /// property does not exist.
        /// </remarks>
        public ConventionTypeConfiguration HasKey(IEnumerable <PropertyInfo> keyProperties)
        {
            Check.NotNull(keyProperties, "keyProperties");
            EntityUtil.CheckArgumentContainsNull(ref keyProperties, "keyProperties");
            EntityUtil.CheckArgumentEmpty(
                ref keyProperties,
                p => Strings.CollectionEmpty(p, "HasKey"), "keyProperties");

            ValidateConfiguration(ConfigurationAspect.HasKey);

            if (_entityTypeConfiguration != null &&
                !_entityTypeConfiguration().IsKeyConfigured)
            {
                _entityTypeConfiguration().Key(keyProperties);
            }

            return(this);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.StoreItemCollection" /> class using the specified XMLReader.
        /// </summary>
        /// <param name="xmlReaders">The XMLReader used to create metadata.</param>
        public StoreItemCollection(IEnumerable <XmlReader> xmlReaders)
            : base(DataSpace.SSpace)
        {
            Check.NotNull(xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReader");

            var composite = MetadataArtifactLoader.CreateCompositeFromXmlReaders(xmlReaders);

            Init(
                composite.GetReaders(),
                composite.GetPaths(),
                /* throwOnError */ true,
                /* resolver */ null,
                out _providerManifest,
                out _providerFactory,
                out _providerInvariantName,
                out _providerManifestToken,
                out _cachedCTypeFunction);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced by System.Data.Entity.Design.dll
        internal StoreItemCollection(IEnumerable <XmlReader> xmlReaders,
                                     System.Collections.ObjectModel.ReadOnlyCollection <string> filePaths,
                                     out IList <EdmSchemaError> errors)
            : base(DataSpace.SSpace)
        {
            // we will check the parameters for this internal ctor becuase
            // it is pretty much publicly exposed through the MetadataItemCollectionFactory
            // in System.Data.Entity.Design
            EntityUtil.CheckArgumentNull(xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentContainsNull(ref xmlReaders, "xmlReaders");
            EntityUtil.CheckArgumentEmpty(ref xmlReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "xmlReader");
            // filePaths is allowed to be null

            errors = this.Init(xmlReaders, filePaths, false,
                               out _providerManifest,
                               out _providerFactory,
                               out _providerManifestToken,
                               out _cachedCTypeFunction);
        }
Beispiel #12
0
        //For MetadataArtifactLoader.CreateCompositeFromFilePaths method call but we do not create the file paths in this method
        public StoreItemCollection(params string[] filePaths)
            : base(DataSpace.SSpace)
        {
            Check.NotNull(filePaths, "filePaths");
            IEnumerable <string> enumerableFilePaths = filePaths;

            EntityUtil.CheckArgumentEmpty(ref enumerableFilePaths, Strings.StoreItemCollectionMustHaveOneArtifact, "filePaths");

            // Wrap the file paths in instances of the MetadataArtifactLoader class, which provides
            // an abstraction and a uniform interface over a diverse set of metadata artifacts.
            //
            MetadataArtifactLoader composite = null;
            List <XmlReader>       readers   = null;

            try
            {
                composite = MetadataArtifactLoader.CreateCompositeFromFilePaths(enumerableFilePaths, XmlConstants.SSpaceSchemaExtension);
                readers   = composite.CreateReaders(DataSpace.SSpace);
                var ieReaders = readers.AsEnumerable();
                EntityUtil.CheckArgumentEmpty(ref ieReaders, Strings.StoreItemCollectionMustHaveOneArtifact, "filePaths");

                Init(
                    readers,
                    composite.GetPaths(DataSpace.SSpace), /* throwOnError */ true, /* resolver */ null,
                    out _providerManifest,
                    out _providerFactory,
                    out _providerInvariantName,
                    out _providerManifestToken,
                    out _cachedCTypeFunction);
            }
            finally
            {
                if (readers != null)
                {
                    Helper.DisposeXmlReaders(readers);
                }
            }
        }
Beispiel #13
0
 internal StoreItemCollection(IEnumerable <XmlReader> xmlReaders, IEnumerable <string> filePaths)
     : base(DataSpace.SSpace)
 {
     EntityUtil.CheckArgumentEmpty <XmlReader>(ref xmlReaders, new Func <string, string>(Strings.StoreItemCollectionMustHaveOneArtifact), "xmlReader");
     this.Init(xmlReaders, filePaths, true, (IDbDependencyResolver)null, out this._providerManifest, out this._providerFactory, out this._providerInvariantName, out this._providerManifestToken, out this._cachedCTypeFunction);
 }