internal DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate)
            : base(metadata, dataSpace, target)
        {
            EntityUtil.CheckArgumentNull(predicate, "predicate");

            this._predicate = predicate;
        }
        internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target)
            : base(metadata, dataSpace)
        {
            Contract.Requires(target != null);

            _target = target;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DbDeleteCommandTree"/> class.
        /// </summary>
        /// <param name="metadata">The model this command will operate on.</param>
        /// <param name="dataSpace">The data space.</param>
        /// <param name="target">The target table for the data manipulation language (DML) operation.</param>
        /// <param name="predicate">A predicate used to determine which members of the target collection should be deleted.</param>
        public DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate)
            : base(metadata, dataSpace, target)
        {
            DebugCheck.NotNull(predicate);

            _predicate = predicate;
        }
        internal DbDeleteCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate)
            : base(metadata, dataSpace, target)
        {
            Contract.Requires(predicate != null);

            _predicate = predicate;
        }
        internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target)
            : base(metadata, dataSpace)
        {
            DebugCheck.NotNull(target);

            _target = target;
        }
        /// <summary>
        /// Initializes a new command tree with a given metadata workspace.
        /// </summary>
        /// <param name="metadata">The metadata workspace against which the command tree should operate.</param>
        /// <param name="dataSpace">The logical 'space' that metadata in the expressions used in this command tree must belong to.</param>
        internal DbCommandTree(MetadataWorkspace metadata, DataSpace dataSpace)
        {
            // Ensure the metadata workspace is non-null
            EntityUtil.CheckArgumentNull(metadata, "metadata");

            // Ensure that the data space value is valid
            if (!DbCommandTree.IsValidDataSpace(dataSpace))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_CommandTree_InvalidDataSpace, "dataSpace");
            }

            //
            // Create the tree's metadata workspace and initalize commonly used types.
            //
            MetadataWorkspace effectiveMetadata = new MetadataWorkspace();
                
            //While EdmItemCollection and StorageitemCollections are required
            //ObjectItemCollection may or may not be registered on the workspace yet.
            //So register the ObjectItemCollection if it exists.
            ItemCollection objectItemCollection;
            if (metadata.TryGetItemCollection(DataSpace.OSpace, out objectItemCollection))
            {
                effectiveMetadata.RegisterItemCollection(objectItemCollection);
            }                
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.CSpace));
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.CSSpace));
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.SSpace));

            this._metadata = effectiveMetadata;
            this._dataSpace = dataSpace;
        }
        /// <summary>
        /// Initializes a new command tree with a given metadata workspace.
        /// </summary>
        /// <param name="metadata">The metadata workspace against which the command tree should operate.</param>
        /// <param name="dataSpace">The logical 'space' that metadata in the expressions used in this command tree must belong to.</param>
        internal DbCommandTree(MetadataWorkspace metadata, DataSpace dataSpace)
        {
            // Ensure the metadata workspace is non-null
            //Contract.Requires(metadata != null);

            // Ensure that the data space value is valid
            if (!IsValidDataSpace(dataSpace))
            {
                throw new ArgumentException(Strings.Cqt_CommandTree_InvalidDataSpace, "dataSpace");
            }

            //
            // Create the tree's metadata workspace and initalize commonly used types.
            //
            var effectiveMetadata = new MetadataWorkspace();

            //While EdmItemCollection and StorageitemCollections are required
            //ObjectItemCollection may or may not be registered on the workspace yet.
            //So register the ObjectItemCollection if it exists.
            ItemCollection objectItemCollection;
            if (metadata.TryGetItemCollection(DataSpace.OSpace, out objectItemCollection))
            {
                effectiveMetadata.RegisterItemCollection(objectItemCollection);
            }
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.CSpace));
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.CSSpace));
            effectiveMetadata.RegisterItemCollection(metadata.GetItemCollection(DataSpace.SSpace));

            _metadata = effectiveMetadata;
            _dataSpace = dataSpace;
        }
        // <summary>
        // Search for a Mapping metadata with the specified type key.
        // </summary>
        // <param name="identity"> identity of the type </param>
        // <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
        // <param name="ignoreCase"> true for case-insensitive lookup </param>
        // <exception cref="ArgumentException">Thrown if mapping space is not valid</exception>
        internal virtual MappingBase GetMap(string identity, DataSpace typeSpace, bool ignoreCase)
        {
            DebugCheck.NotNull(identity);

            //will only be implemented by Mapping Item Collections
            throw Error.NotSupported();
        }
 /// <summary>
 /// Initializes a new instance of relationship type
 /// </summary>
 /// <param name="name">name of the relationship type</param>
 /// <param name="namespaceName">namespace of the relationship type</param>
 /// <param name="version">version of the relationship type</param>
 /// <param name="dataSpace">dataSpace in which this edmtype belongs to</param>
 /// <exception cref="System.ArgumentNullException">Thrown if either name, namespace or version arguments are null</exception>
 internal RelationshipType(
     string name,
     string namespaceName,
     DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
 }
        /// <summary>
        /// Returns the stream of the XSD corresponding to the frameworkVersion, and dataSpace passed in.
        /// </summary>
        /// <param name="entityFrameworkVersion">The version of the EntityFramework that you want the Schema XSD for.</param>
        /// <param name="dataSpace">The data space of the schem XSD that you want.</param>
        /// <returns>Stream version of the XSD</returns>
        public static Stream GetSchemaXsd(Version entityFrameworkVersion, DataSpace dataSpace)
        {
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(entityFrameworkVersion, "entityFrameworkVersion");

            string resourceName = null;
            switch(dataSpace)
            {
                case DataSpace.CSpace:
                    resourceName =  GetEdmSchemaXsdResourceName(entityFrameworkVersion);
                    break;
                case DataSpace.CSSpace:
                    resourceName =  GetMappingSchemaXsdResourceName(entityFrameworkVersion);
                    break;
                case DataSpace.SSpace:
                    resourceName =  GetStoreSchemaXsdResourceName(entityFrameworkVersion);
                    break;
                default:
                    throw EDesignUtil.Argument("dataSpace");
            }

            Debug.Assert(!string.IsNullOrEmpty(resourceName), "Did you forget to map something new?");

            Assembly dataEntity = typeof(EdmItemCollection).Assembly;
            return dataEntity.GetManifestResourceStream(resourceName);
        }
        internal DbModificationCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target)
            : base(metadata, dataSpace)
        {
            EntityUtil.CheckArgumentNull(target, "target");

            this._target = target;
        }
 public override void CollectFilePermissionPaths(List<string> paths, DataSpace spaceToGet)
 {
     foreach (var loader in _children)
     {
         loader.CollectFilePermissionPaths(paths, spaceToGet);
     }
 }
        /// <summary>
        /// Search for a Mapping metadata with the specified type key.
        /// </summary>
        /// <param name="identity">identity of the type</param>
        /// <param name="typeSpace">The dataspace that the type for which map needs to be returned belongs to</param>
        /// <param name="ignoreCase">true for case-insensitive lookup</param>
        /// <exception cref="ArgumentException"> Thrown if mapping space is not valid</exception>
        internal virtual Map GetMap(string identity, DataSpace typeSpace, bool ignoreCase)
        {
            Contract.Requires(identity != null);

            //will only be implemented by Mapping Item Collections
            throw Error.NotSupported();
        }
        public EdmModel(EntityContainer entityContainer, double version = XmlConstants.SchemaVersionLatest)
        {
            Check.NotNull(entityContainer, "entityContainer");

            _dataSpace = entityContainer.DataSpace;
            _containers.Add(entityContainer);
            SchemaVersion = version;
        }
Exemple #15
0
        /// <summary>
        /// Creates a new instance of perspective class so that query can work
        /// ignorant of all spaces
        /// </summary>
        /// <param name="metadataWorkspace">runtime metadata container</param>
        /// <param name="targetDataspace">target dataspace for the perspective</param>
        internal Perspective(MetadataWorkspace metadataWorkspace,
                             DataSpace targetDataspace)
        {
            EntityUtil.CheckArgumentNull(metadataWorkspace, "metadataWorkspace");

            m_metadataWorkspace = metadataWorkspace;
            m_targetDataspace = targetDataspace;
        }
 public override void CollectFilePermissionPaths(List<string> paths, DataSpace spaceToGet)
 {
     if (!_alreadyLoaded
         && IsArtifactOfDataSpace(_path, spaceToGet))
     {
         paths.Add(_path);
     }
 }
        //Indexes into the type mappings collection based on clr type name

        #endregion

        #region Methods

        /// <summary>
        /// Search for a Mapping metadata with the specified type key.
        /// </summary>
        /// <param name="identity">identity of the type</param>
        /// <param name="typeSpace">The dataspace that the type for which map needs to be returned belongs to</param>
        /// <param name="ignoreCase">true for case-insensitive lookup</param>
        /// <exception cref="ArgumentException"> Thrown if mapping space is not valid</exception>
        internal override Map GetMap(string identity, DataSpace typeSpace, bool ignoreCase)
        {
            Map map;
            if (!TryGetMap(identity, typeSpace, ignoreCase, out map))
            {
                throw new InvalidOperationException(Strings.Mapping_Object_InvalidType(identity));
            }
            return map;
        }
 /// <summary>
 /// Initializes a new instance of Association Type with the given name, namespace, version and ends
 /// </summary>
 /// <param name="name">name of the association type</param>
 /// <param name="namespaceName">namespace of the association type</param>
 /// <param name="foreignKey">is this a foreign key (FK) relationship?</param>
 /// <param name="dataSpace">dataSpace in which this AssociationType belongs to</param>
 /// <exception cref="System.ArgumentNullException">Thrown if either the name, namespace or version attributes are null</exception>
 internal AssociationType(string name,
                          string namespaceName,
                          bool foreignKey,
                          DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
     _referentialConstraints = new ReadOnlyMetadataCollection<ReferentialConstraint>(new MetadataCollection<ReferentialConstraint>());
     _isForeignKey = foreignKey;
 }
        public EntityContainer(string name, DataSpace dataSpace)
        {
            Check.NotEmpty(name, "name");

            _name = name;
            DataSpace = dataSpace;
            _baseEntitySets = new ReadOnlyMetadataCollection<EntitySetBase>(new EntitySetBaseCollection(this));
            _functionImports = new ReadOnlyMetadataCollection<EdmFunction>(new MetadataCollection<EdmFunction>());
        }
        // <summary>
        // Creates a new instance of perspective class so that query can work
        // ignorant of all spaces
        // </summary>
        // <param name="metadataWorkspace"> runtime metadata container </param>
        // <param name="targetDataspace"> target dataspace for the perspective </param>
        internal Perspective(
            MetadataWorkspace metadataWorkspace,
            DataSpace targetDataspace)
        {
            DebugCheck.NotNull(metadataWorkspace);

            _metadataWorkspace = metadataWorkspace;
            _targetDataspace = targetDataspace;
        }
        internal DbInsertCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses, DbExpression returning)
            : base(metadata, dataSpace, target)
        {
            EntityUtil.CheckArgumentNull(setClauses, "setClauses");
            // returning may be null

            this._setClauses = setClauses;
            this._returning = returning;
        }
        /// <summary>
        /// Creates a new instance of perspective class so that query can work
        /// ignorant of all spaces
        /// </summary>
        /// <param name="metadataWorkspace">runtime metadata container</param>
        /// <param name="targetDataspace">target dataspace for the perspective</param>
        internal Perspective(
            MetadataWorkspace metadataWorkspace,
            DataSpace targetDataspace)
        {
            //Contract.Requires(metadataWorkspace != null);

            m_metadataWorkspace = metadataWorkspace;
            m_targetDataspace = targetDataspace;
        }
        /// <summary>
        /// The constructor for constructing the EntityContainer object with the name, namespaceName, and version.
        /// </summary>
        /// <param name="name">The name of this entity container</param>
        /// <param name="dataSpace">dataSpace in which this entity container belongs to</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the name argument is null</exception>
        /// <exception cref="System.ArgumentException">Thrown if the name argument is empty string</exception>
        internal EntityContainer(string name, DataSpace dataSpace)
        {
            EntityUtil.CheckStringArgument(name, "name");

            _name = name;
            this.DataSpace = dataSpace;
            _baseEntitySets = new ReadOnlyMetadataCollection<EntitySetBase>(new EntitySetBaseCollection(this));
            _functionImports = new ReadOnlyMetadataCollection<EdmFunction>(new MetadataCollection<EdmFunction>());
        }
        /// <summary>
        /// Initializes a new instance of the EnumType class by using the specified <paramref name="name"/>,
        /// <paramref name="namespaceName"/> and <paramref name="isFlags"/>.
        /// </summary>
        /// <param name="name">The name of this enum type.</param>
        /// <param name="namespaceName">The namespace this enum type belongs to.</param>
        /// <param name="isFlags">Indicates whether the enum type is defined as flags (i.e. can be treated as a bit field).</param>
        /// <param name="underlyingType">Underlying type of this enumeration type.</param>
        /// <param name="dataSpace">DataSpace this enum type lives in. Can be either CSpace or OSpace</param>
        /// <exception cref="System.ArgumentNullException">Thrown if name or namespace arguments are null</exception>
        /// <remarks>Note that enums live only in CSpace.</remarks>
        internal EnumType(string name, string namespaceName, PrimitiveType underlyingType, bool isFlags, DataSpace dataSpace)
            : base(name, namespaceName, dataSpace)
        { 
            Debug.Assert(underlyingType != null, "underlyingType != null");
            Debug.Assert(Helper.IsSupportedEnumUnderlyingType(underlyingType.PrimitiveTypeKind), "Unsupported underlying type for enum.");
            Debug.Assert(dataSpace == DataSpace.CSpace || dataSpace == DataSpace.OSpace, "Enums can be only defined in CSpace or OSpace.");

            _isFlags = isFlags;
            _underlyingType = underlyingType;
        }
        internal DbUpdateCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, DbExpression predicate, ReadOnlyModificationClauses setClauses, DbExpression returning)
            : base(metadata, dataSpace, target)
        {
            EntityUtil.CheckArgumentNull(predicate, "predicate");
            EntityUtil.CheckArgumentNull(setClauses, "setClauses");
            // returning is allowed to be null

            this._predicate = predicate;
            this._setClauses = setClauses;
            this._returning = returning;
        }
        /// <summary>
        /// Get paths to artifacts for a specific DataSpace.
        /// </summary>
        /// <param name="spaceToGet">The DataSpace for the artifacts of interest</param>
        /// <returns>A List of strings identifying paths to all artifacts for a specific DataSpace</returns>
        public override List<string> GetPaths(DataSpace spaceToGet)
        {
            var list = new List<string>();

            foreach (var resource in _children)
            {
                list.AddRange(resource.GetPaths(spaceToGet));
            }

            return list;
        }
        internal DbInsertCommandTree(
            MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses,
            DbExpression returning)
            : base(metadata, dataSpace, target)
        {
            //Contract.Requires(setClauses != null);
            // returning may be null

            _setClauses = setClauses;
            _returning = returning;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DbInsertCommandTree"/> class.
        /// </summary>
        /// <param name="metadata">The model this command will operate on.</param>
        /// <param name="dataSpace">The data space.</param>
        /// <param name="target">The target table for the data manipulation language (DML) operation.</param>
        /// <param name="setClauses">The list of insert set clauses that define the insert operation. .</param>
        /// <param name="returning">A <see cref="DbExpression"/> that specifies a projection of results to be returned, based on the modified rows.</param>
        public DbInsertCommandTree(
            MetadataWorkspace metadata, DataSpace dataSpace, DbExpressionBinding target, ReadOnlyModificationClauses setClauses,
            DbExpression returning)
            : base(metadata, dataSpace, target)
        {
            DebugCheck.NotNull(setClauses);
            // returning may be null

            _setClauses = setClauses;
            _returning = returning;
        }
 [ResourceExposure(ResourceScope.Machine)] //Exposes the file paths which are a Machine resource
 public override void CollectFilePermissionPaths(List<string> paths, DataSpace spaceToGet)
 {
    IList<MetadataArtifactLoaderFile> files;
     if(TryGetListForSpace(spaceToGet, out files))
     {
         foreach(var loader in files)
         {
             loader.CollectFilePermissionPaths(paths, spaceToGet);
         }
     }
 }
        private static Mock<EdmFunction> CreateMockEdmFunction(DataSpace dataSpace, string namespaceName)
        {
            var mockProperty = new Mock<MetadataProperty>();
            mockProperty.Setup(m => m.Name).Returns("DataSpace");
            mockProperty.Setup(m => m.Value).Returns(dataSpace);

            var mockEdmFunction = new Mock<EdmFunction>();
            mockEdmFunction.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection<MetadataProperty>(new[] { mockProperty.Object }));
            mockEdmFunction.Setup(m => m.NamespaceName).Returns(namespaceName);

            return mockEdmFunction;
        }
Exemple #31
0
        /// <summary>
        /// Constructs a new DbFunctionCommandTree that uses the specified metadata workspace, data space and function metadata
        /// </summary>
        /// <param name="metadata">The metadata workspace that the command tree should use.</param>
        /// <param name="dataSpace">The logical 'space' that metadata in the expressions used in this command tree must belong to.</param>
        /// <param name="edmFunction"></param>
        /// <param name="resultType"></param>
        /// <param name="parameters"></param>
        /// <exception cref="ArgumentNullException"><paramref name="metadata"/>, <paramref name="dataSpace"/> or <paramref name="edmFunction"/> is null</exception>
        /// <exception cref="ArgumentException"><paramref name="dataSpace"/> does not represent a valid data space or
        /// <paramref name="edmFunction">is a composable function</paramref></exception>
        /*CQT_PUBLIC_API(*/ internal /*)*/ DbFunctionCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, EdmFunction edmFunction, TypeUsage resultType, IEnumerable <KeyValuePair <string, TypeUsage> > parameters)
            : base(metadata, dataSpace)
        {
            EntityUtil.CheckArgumentNull(edmFunction, "edmFunction");

            _edmFunction = edmFunction;
            _resultType  = resultType;

            List <string>    paramNames = new List <string>();
            List <TypeUsage> paramTypes = new List <TypeUsage>();

            if (parameters != null)
            {
                foreach (KeyValuePair <string, TypeUsage> paramInfo in parameters)
                {
                    paramNames.Add(paramInfo.Key);
                    paramTypes.Add(paramInfo.Value);
                }
            }

            _parameterNames = paramNames.AsReadOnly();
            _parameterTypes = paramTypes.AsReadOnly();
        }
 /// <summary>
 ///     Constructs a new DbQueryCommandTree that uses the specified metadata workspace.
 /// </summary>
 /// <param name="metadata"> The metadata workspace that the command tree should use. </param>
 /// <param name="dataSpace"> The logical 'space' that metadata in the expressions used in this command tree must belong to. </param>
 /// <param name="query">
 ///     A <see cref="DbExpression" /> that defines the logic of the query.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="metadata" />
 ///     or
 ///     <paramref name="query" />
 ///     is null
 /// </exception>
 /// <exception cref="ArgumentException">
 ///     <paramref name="dataSpace" />
 ///     does not represent a valid data space
 /// </exception>
 public DbQueryCommandTree(MetadataWorkspace metadata, DataSpace dataSpace, DbExpression query)
     : this(metadata, dataSpace, query, true)
 {
 }
 internal EdmType(string name, string namespaceName, DataSpace dataSpace)
 {
     Check.NotNull <string>(name, nameof(name));
     Check.NotNull <string>(namespaceName, nameof(namespaceName));
     EdmType.Initialize(this, name, namespaceName, dataSpace, false, (EdmType)null);
 }
 internal EdmFunction(string name, string namespaceName, DataSpace dataSpace)
     : this(name, namespaceName, dataSpace, new EdmFunctionPayload())
 {
 }
Exemple #35
0
        // <summary>
        // Search for a Mapping metadata with the specified type key.
        // </summary>
        // <param name="identity"> identity of the type </param>
        // <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
        // <param name="ignoreCase"> true for case-insensitive lookup </param>
        // <returns> Returns false if no match found. </returns>
        internal override bool TryGetMap(string identity, DataSpace typeSpace, bool ignoreCase, out MappingBase map)
        {
            EdmType cdmType = null;
            EdmType clrType = null;

            if (typeSpace == DataSpace.CSpace)
            {
                if (ignoreCase)
                {
                    // Get the correct casing of the identity first if we are asked to do ignore case
                    if (!_edmCollection.TryGetItem(identity, true, out cdmType))
                    {
                        map = null;
                        return(false);
                    }

                    identity = cdmType.Identity;
                }

                int index;
                if (_edmTypeIndexes.TryGetValue(identity, out index))
                {
                    map = (MappingBase)this[index];
                    return(true);
                }

                if (cdmType != null
                    ||
                    _edmCollection.TryGetItem(identity, ignoreCase, out cdmType))
                {
                    // If the mapping is not already loaded, then get the mapping ospace type
                    _objectCollection.TryGetOSpaceType(cdmType, out clrType);
                }
            }
            else if (typeSpace == DataSpace.OSpace)
            {
                if (ignoreCase)
                {
                    // Get the correct casing of the identity first if we are asked to do ignore case
                    if (!_objectCollection.TryGetItem(identity, true, out clrType))
                    {
                        map = null;
                        return(false);
                    }

                    identity = clrType.Identity;
                }

                int index;
                if (_clrTypeIndexes.TryGetValue(identity, out index))
                {
                    map = (MappingBase)this[index];
                    return(true);
                }

                if (clrType != null
                    ||
                    _objectCollection.TryGetItem(identity, ignoreCase, out clrType))
                {
                    // If the mapping is not already loaded, get the mapping cspace type
                    var cspaceTypeName = ObjectItemCollection.TryGetMappingCSpaceTypeIdentity(clrType);
                    _edmCollection.TryGetItem(cspaceTypeName, out cdmType);
                }
            }

            if ((clrType == null) ||
                (cdmType == null))
            {
                map = null;
                return(false);
            }
            else
            {
                map = GetDefaultMapping(cdmType, clrType);
                return(true);
            }
        }
Exemple #36
0
 /// <summary>
 ///     Initializes a new instance of Complex Type with the given properties
 /// </summary>
 /// <param name="name"> The name of the complex type </param>
 /// <param name="namespaceName"> The namespace name of the type </param>
 /// <param name="version"> The version of this type </param>
 /// <param name="dataSpace"> dataSpace in which this ComplexType belongs to </param>
 /// <exception cref="System.ArgumentNullException">If either name, namespace or version arguments are null</exception>
 public ComplexType(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
 }
Exemple #37
0
        public static DbExpression Convert(DynamicFilterDefinition filter, DbExpressionBinding binding, DbContext dbContext, DataSpace dataSpace)
        {
            var visitor    = new LambdaToDbExpressionVisitor(filter, binding, dbContext, dataSpace);
            var expression = visitor.Visit(filter.Predicate) as LambdaExpression;

            var dbExpression = visitor.GetDbExpressionForExpression(expression.Body);

            if (dbExpression is DbPropertyExpression)
            {
                //  Special case to handle a condition that is just a plain "boolFlag" or a nullable generic condition.
                //  For a nullable type, we only get here when the filter has either not specified a value for the nullable
                //  parameter or it has specified "null" - both evaluate the same as far as the method prototypes can tell
                //  since the method signature is "param = null".  This needs to generate a sql "is null" condition.
                //  Otherwise, no param value was specified so we are assuming that we need to generate a "positive"
                //  condition.  i.e. the filter just said "b.prop" which generally means "b.prop == true".
                //  To generate that condition correctly for all types (may not necessarily be a bool), we create a condition
                //  like "!(b.prop == [defaultValue])"

                if (IsNullableType(expression.Body.Type))
                {
                    dbExpression = DbExpressionBuilder.IsNull(dbExpression);
                }
                else
                {
                    var defaultValue = DbExpressionBuilder.Constant(dbExpression.ResultType, Activator.CreateInstance(expression.Body.Type));
                    dbExpression = DbExpressionBuilder.Not(DbExpressionBuilder.Equal(dbExpression, defaultValue));
                }
            }

            return(dbExpression);
        }
Exemple #38
0
        internal static bool TryGetSchemaVersion(string xmlNamespaceName, out double version, out DataSpace dataSpace)
        {
            switch (xmlNamespaceName)
            {
            case XmlConstants.ModelNamespace_1:
                version   = XmlConstants.EdmVersionForV1;
                dataSpace = DataSpace.CSpace;
                return(true);

            case XmlConstants.ModelNamespace_1_1:
                version   = XmlConstants.EdmVersionForV1_1;
                dataSpace = DataSpace.CSpace;
                return(true);

            case XmlConstants.ModelNamespace_2:
                version   = XmlConstants.EdmVersionForV2;
                dataSpace = DataSpace.CSpace;
                return(true);

            case XmlConstants.ModelNamespace_3:
                version   = XmlConstants.EdmVersionForV3;
                dataSpace = DataSpace.CSpace;
                return(true);

            case XmlConstants.TargetNamespace_1:
                version   = XmlConstants.StoreVersionForV1;
                dataSpace = DataSpace.SSpace;
                return(true);

            case XmlConstants.TargetNamespace_2:
                version   = XmlConstants.StoreVersionForV2;
                dataSpace = DataSpace.SSpace;
                return(true);

            case XmlConstants.TargetNamespace_3:
                version   = XmlConstants.StoreVersionForV3;
                dataSpace = DataSpace.SSpace;
                return(true);

            case StorageMslConstructs.NamespaceUriV1:
                version   = StorageMslConstructs.MappingVersionV1;
                dataSpace = DataSpace.CSSpace;
                return(true);

            case StorageMslConstructs.NamespaceUriV2:
                version   = StorageMslConstructs.MappingVersionV2;
                dataSpace = DataSpace.CSSpace;
                return(true);

            case StorageMslConstructs.NamespaceUriV3:
                version   = StorageMslConstructs.MappingVersionV3;
                dataSpace = DataSpace.CSSpace;
                return(true);

            default:
                version   = default(Double);
                dataSpace = default(DataSpace);
                return(false);
            }
        }
Exemple #39
0
        private MappingBase GetOCMapForTransientType(EdmType edmType, DataSpace typeSpace)
        {
            Debug.Assert(
                typeSpace == DataSpace.CSpace || typeSpace == DataSpace.OSpace || Helper.IsRowType(edmType) ||
                Helper.IsCollectionType(edmType));
            EdmType clrType = null;
            EdmType cdmType = null;
            var     index   = -1;

            if (typeSpace != DataSpace.OSpace)
            {
                if (_edmTypeIndexes.TryGetValue(edmType.Identity, out index))
                {
                    return((MappingBase)this[index]);
                }
                else
                {
                    cdmType = edmType;
                    clrType = ConvertCSpaceToOSpaceType(edmType);
                }
            }
            else if (typeSpace == DataSpace.OSpace)
            {
                if (_clrTypeIndexes.TryGetValue(edmType.Identity, out index))
                {
                    return((MappingBase)this[index]);
                }
                else
                {
                    clrType = edmType;
                    cdmType = ConvertOSpaceToCSpaceType(clrType);
                }
            }

            var typeMapping = new ObjectTypeMapping(clrType, cdmType);

            if (BuiltInTypeKind.RowType
                == edmType.BuiltInTypeKind)
            {
                var clrRowType = (RowType)clrType;
                var edmRowType = (RowType)cdmType;

                Debug.Assert(clrRowType.Properties.Count == edmRowType.Properties.Count, "Property count mismatch");
                for (var idx = 0; idx < clrRowType.Properties.Count; idx++)
                {
                    typeMapping.AddMemberMap(new ObjectPropertyMapping(edmRowType.Properties[idx], clrRowType.Properties[idx]));
                }
            }
            if ((!_edmTypeIndexes.ContainsKey(cdmType.Identity)) &&
                (!_clrTypeIndexes.ContainsKey(clrType.Identity)))
            {
                lock (_lock)
                {
                    var clrTypeIndexes = new Dictionary <string, int>(_clrTypeIndexes);
                    var edmTypeIndexes = new Dictionary <string, int>(_edmTypeIndexes);

                    typeMapping = AddInternalMapping(typeMapping, clrTypeIndexes, edmTypeIndexes);

                    _clrTypeIndexes = clrTypeIndexes;
                    _edmTypeIndexes = edmTypeIndexes;
                }
            }
            return(typeMapping);
        }
 public override void CollectFilePermissionPaths(List <string> paths, DataSpace spaceToGet)
 {
     // no op
 }
Exemple #41
0
 // <summary>
 // Search for a Mapping metadata with the specified type key.
 // </summary>
 // <param name="identity"> identity of the type </param>
 // <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
 // <exception cref="ArgumentException">Thrown if mapping space is not valid</exception>
 internal override MappingBase GetMap(string identity, DataSpace typeSpace)
 {
     return(GetMap(identity, typeSpace, false /*ignoreCase*/));
 }
Exemple #42
0
 internal void SetDataSpace(DataSpace space)
 {
     _flags = (_flags & ~MetadataFlags.DataSpace) | (MetadataFlags.DataSpace & Convert(space));
 }
 internal EntityTypeBase(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
     this._keyMembers = new ReadOnlyMetadataCollection <EdmMember>(new MetadataCollection <EdmMember>());
 }
Exemple #44
0
        /// <summary>
        ///     Initializes a new instance of the EnumType class by using the specified <paramref name="name" />,
        ///     <paramref name="namespaceName" /> and <paramref name="isFlags" />.
        /// </summary>
        /// <param name="name"> The name of this enum type. </param>
        /// <param name="namespaceName"> The namespace this enum type belongs to. </param>
        /// <param name="isFlags"> Indicates whether the enum type is defined as flags (i.e. can be treated as a bit field). </param>
        /// <param name="underlyingType"> Underlying type of this enumeration type. </param>
        /// <param name="dataSpace"> DataSpace this enum type lives in. Can be either CSpace or OSpace </param>
        /// <exception cref="System.ArgumentNullException">Thrown if name or namespace arguments are null</exception>
        /// <remarks>
        ///     Note that enums live only in CSpace.
        /// </remarks>
        internal EnumType(string name, string namespaceName, PrimitiveType underlyingType, bool isFlags, DataSpace dataSpace)
            : base(name, namespaceName, dataSpace)
        {
            DebugCheck.NotNull(underlyingType);
            Debug.Assert(Helper.IsSupportedEnumUnderlyingType(underlyingType.PrimitiveTypeKind), "Unsupported underlying type for enum.");
            Debug.Assert(dataSpace == DataSpace.CSpace || dataSpace == DataSpace.OSpace, "Enums can be only defined in CSpace or OSpace.");

            _isFlags        = isFlags;
            _underlyingType = underlyingType;
        }
Exemple #45
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;
            _fullName   = this.NamespaceName + "." + this.Name;

            FunctionParameter[] returnParameters = payload.ReturnParameters;

            Debug.Assert(returnParameters.All((returnParameter) => returnParameter != null), "All return parameters must be non-null");
            Debug.Assert(returnParameters.All((returnParameter) => returnParameter.Mode == ParameterMode.ReturnValue), "Return parameter in a function must have the ParameterMode equal to ReturnValue.");

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select((returnParameter) => SafeLink <EdmFunction> .BindChild <FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                Debug.Assert(_returnParameters.Count == payload.EntitySets.Length, "The number of entity sets should match the number of return parameters");
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                var list = new List <EntitySet>();
                if (_returnParameters.Count != 0)
                {
                    Debug.Assert(_returnParameters.Count == 1, "If there was more than one result set payload.EntitySets should not have been null");
                    list.Add(null);
                }
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(list);
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (FunctionParameter parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw EntityUtil.CollectionParameterElementIsNull("parameters");
                    }
                    Debug.Assert(parameter.Mode != ParameterMode.ReturnValue, "No function parameter can have ParameterMode equal to ReturnValue.");
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
Exemple #46
0
        // this method will move skip down to the first element, or to the end if it doesn't find one
        internal static bool TryGetSchemaVersion(XmlReader reader, out double version, out DataSpace dataSpace)
        {
            // to make life simpler, we skip down to the first/root element, unless we're
            // already there
            if (!reader.EOF &&
                reader.NodeType != XmlNodeType.Element)
            {
                while (reader.Read() &&
                       reader.NodeType != XmlNodeType.Element)
                {
                }
            }

            if (!reader.EOF
                &&
                (reader.LocalName == XmlConstants.Schema || reader.LocalName == StorageMslConstructs.MappingElement))
            {
                return(TryGetSchemaVersion(reader.NamespaceURI, out version, out dataSpace));
            }

            version   = default(double);
            dataSpace = default(DataSpace);
            return(false);
        }
Exemple #47
0
        public static TypeUsage TypeUsageForPrimitiveType(Type type, ObjectContext objectContext, DataSpace dataSpace)
        {
            bool isNullable = IsNullableType(type);

            type = PrimitiveTypeForType(type, dataSpace);

            //  Find equivalent EdmType in CSpace.  This is a 1-to-1 mapping to CLR types except for the Geometry/Geography types
            //  (so not supporting those atm).
            EdmType edmType;

            if (dataSpace == DataSpace.CSpace)
            {
                if (type.IsEnum)
                {
                    edmType = objectContext.MetadataWorkspace.GetItems <EnumType>(DataSpace.CSpace).FirstOrDefault(e => e.MetadataProperties.Any(m => m.Name.EndsWith(":ClrType") && (Type)m.Value == type));
                    if (edmType == null)
                    {
                        throw new ApplicationException(string.Format("Unable to map parameter of type {0} to TypeUsage", type.FullName));
                    }
                }
                else
                {
                    var primitiveTypeList = objectContext.MetadataWorkspace
                                            .GetPrimitiveTypes(DataSpace.CSpace)
                                            .Where(p => p.ClrEquivalentType == type)
                                            .ToList();
                    if (primitiveTypeList.Count != 1)
                    {
                        throw new ApplicationException(string.Format("Unable to map parameter of type {0} to TypeUsage.  Found {1} matching types", type.Name, primitiveTypeList.Count));
                    }
                    edmType = primitiveTypeList.FirstOrDefault();
                }
            }
            else
            {
                var primitiveTypeList = objectContext.MetadataWorkspace
                                        .GetPrimitiveTypes(DataSpace.CSpace)
                                        .Where(p => p.ClrEquivalentType == type)
                                        .ToList();
                if (primitiveTypeList.Count != 1)
                {
                    throw new ApplicationException(string.Format("Unable to map parameter of type {0} to TypeUsage.  Found {1} matching types", type.Name, primitiveTypeList.Count));
                }
                edmType = primitiveTypeList.FirstOrDefault();
            }

            var facetList = new List <Facet>();

            if (isNullable)
            {
                //  May not even be necessary to specify these Facets, but just to be safe.  And only way to create them is to call the internal Create method...
                var createMethod = typeof(Facet).GetMethod("Create", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(FacetDescription), typeof(object) }, null);

                var facetDescription = Facet.GetGeneralFacetDescriptions().FirstOrDefault(fd => fd.FacetName == "Nullable");
                if (facetDescription != null)
                {
                    facetList.Add((Facet)createMethod.Invoke(null, new object[] { facetDescription, true }));
                }

                facetDescription = Facet.GetGeneralFacetDescriptions().FirstOrDefault(fd => fd.FacetName == "DefaultValue");
                if (facetDescription != null)
                {
                    facetList.Add((Facet)createMethod.Invoke(null, new object[] { facetDescription, null }));
                }
            }

            return(TypeUsage.Create(edmType, facetList));
        }
Exemple #48
0
 /// <summary>
 /// The constructor for SimpleType.  It takes the required information to identify this type.
 /// </summary>
 /// <param name="name">The name of this type</param>
 /// <param name="namespaceName">The namespace name of this type</param>
 /// <param name="dataSpace">dataspace in which the simple type belongs to</param>
 /// <exception cref="System.ArgumentNullException">Thrown if either name, namespace or version arguments are null</exception>
 internal SimpleType(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
 }
Exemple #49
0
 private LambdaToDbExpressionVisitor(DynamicFilterDefinition filter, DbExpressionBinding binding, DbContext dbContext, DataSpace dataSpace)
 {
     _Filter        = filter;
     _Binding       = binding;
     _DbContext     = dbContext;
     _ObjectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
     _DataSpace     = dataSpace;
 }
Exemple #50
0
 /// <summary>
 ///     Initializes a new instance of Structural Type with the given members
 /// </summary>
 /// <param name="name"> name of the structural type </param>
 /// <param name="namespaceName"> namespace of the structural type </param>
 /// <param name="version"> version of the structural type </param>
 /// <param name="dataSpace"> dataSpace in which this edmtype belongs to </param>
 /// <exception cref="System.ArgumentNullException">Thrown if either name, namespace or version arguments are null</exception>
 internal StructuralType(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
     _members         = new MemberCollection(this);
     _readOnlyMembers = _members.AsReadOnlyMetadataCollection();
 }
        internal EdmFunction(
            string name,
            string namespaceName,
            DataSpace dataSpace,
            EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            this._schemaName = payload.Schema;
            IList <FunctionParameter> source = payload.ReturnParameters ?? (IList <FunctionParameter>) new FunctionParameter[0];

            foreach (FunctionParameter functionParameter in (IEnumerable <FunctionParameter>)source)
            {
                if (functionParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(ReturnParameters)));
                }
                if (functionParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }
            this._returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(source.Select <FunctionParameter, FunctionParameter>((Func <FunctionParameter, FunctionParameter>)(returnParameter => SafeLink <EdmFunction> .BindChild <FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))).ToList <FunctionParameter>());
            if (payload.IsAggregate.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }
            if (payload.ParameterTypeSemantics.HasValue)
            {
                this._parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }
            if (payload.StoreFunctionName != null)
            {
                this._storeFunctionNameAttribute = payload.StoreFunctionName;
            }
            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != source.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (this._returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>((IList <EntitySet>) this._returnParameters.Select <FunctionParameter, EntitySet>((Func <FunctionParameter, EntitySet>)(p => (EntitySet)null)).ToList <EntitySet>());
            }
            if (payload.CommandText != null)
            {
                this._commandTextAttribute = payload.CommandText;
            }
            if (payload.Parameters != null)
            {
                foreach (FunctionParameter parameter in (IEnumerable <FunctionParameter>)payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)"parameters"));
                    }
                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }
                this._parameters = (ReadOnlyMetadataCollection <FunctionParameter>) new SafeLinkCollection <EdmFunction, FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>((IEnumerable <FunctionParameter>)payload.Parameters));
            }
            else
            {
                this._parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
 /// <summary>
 ///     Search for a Mapping metadata with the specified type key.
 /// </summary>
 /// <param name="identity"> identity of the type </param>
 /// <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
 /// <param name="ignoreCase"> true for case-insensitive lookup </param>
 /// <param name="map"> </param>
 /// <returns> Returns false if no match found. </returns>
 internal virtual bool TryGetMap(string identity, DataSpace typeSpace, bool ignoreCase, out Map map)
 {
     //will only be implemented by Mapping Item Collections
     throw Error.NotSupported();
 }
 // <summary>
 // Get paths to artifacts for a specific DataSpace, in the original, unexpanded
 // form.
 // </summary>
 // <remarks>
 // A filesystem folder can contain any kind of artifact, so we simply
 // ignore the parameter and return the original path to the folder.
 // </remarks>
 // <param name="spaceToGet"> The DataSpace for the artifacts of interest </param>
 // <returns> A List of strings identifying paths to all artifacts for a specific DataSpace </returns>
 public override List <string> GetOriginalPaths(DataSpace spaceToGet)
 {
     return(GetOriginalPaths());
 }
 /// <summary>
 ///     The default constructor for ItemCollection
 /// </summary>
 internal MappingItemCollection(DataSpace dataSpace)
     : base(dataSpace)
 {
 }
Exemple #55
0
 // <summary>
 // The default constructor for ItemCollection
 // </summary>
 internal ItemCollection(DataSpace dataspace)
     : base(new MetadataCollection <GlobalItem>())
 {
     _space = dataspace;
 }
 // <summary>
 // Get XmlReaders for a specific DataSpace.
 // </summary>
 // <param name="spaceToGet"> The DataSpace for the artifacts of interest </param>
 // <returns> A List of XmlReader object </returns>
 public abstract List <XmlReader> CreateReaders(DataSpace spaceToGet);
Exemple #57
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;

            var returnParameters = payload.ReturnParameters ?? new FunctionParameter[0];

            foreach (var returnParameter in returnParameters)
            {
                if (returnParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("ReturnParameters"));
                }

                if (returnParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select(
                    returnParameter =>
                    SafeLink <EdmFunction> .BindChild(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(
                    ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != returnParameters.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (_returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(_returnParameters.Select(p => (EntitySet)null).ToList());
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (var parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("parameters"));
                    }

                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(
                    this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
Exemple #58
0
 // <summary>
 // Initializes a new instance of Entity Type
 // </summary>
 // <param name="name"> name of the entity type </param>
 // <param name="namespaceName"> namespace of the entity type </param>
 // <param name="dataSpace"> dataspace in which the EntityType belongs to </param>
 // <exception cref="System.ArgumentNullException">Thrown if either name, namespace or version arguments are null</exception>
 internal EntityType(string name, string namespaceName, DataSpace dataSpace)
     : base(name, namespaceName, dataSpace)
 {
 }
        internal static DbQueryCommandTree FromValidExpression(MetadataWorkspace metadata, DataSpace dataSpace, DbExpression query)
        {
#if DEBUG
            return(new DbQueryCommandTree(metadata, dataSpace, query));
#else
            return(new DbQueryCommandTree(metadata, dataSpace, query, false));
#endif
        }
Exemple #60
0
 // <summary>
 // Search for a Mapping metadata with the specified type key.
 // </summary>
 // <param name="identity"> identity of the type </param>
 // <param name="typeSpace"> The dataspace that the type for which map needs to be returned belongs to </param>
 // <returns> Returns false if no match found. </returns>
 internal override bool TryGetMap(string identity, DataSpace typeSpace, out MappingBase map)
 {
     return(TryGetMap(identity, typeSpace, false /*ignoreCase*/, out map));
 }