Ejemplo n.º 1
0
        public override void Visit(SoftCastOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefs = (PropertyRefList)null;

            if (TypeSemantics.IsReferenceType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            else if (TypeSemantics.IsNominalType(op.Type))
            {
                propertyRefs = this.m_nodePropertyRefMap[n].Clone();
            }
            else if (TypeSemantics.IsRowType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            if (propertyRefs != null)
            {
                this.AddPropertyRefs(n.Child0, propertyRefs);
            }
            this.VisitChildren(n);
        }
Ejemplo n.º 2
0
        private void WriteFunctionElement(EdmFunction function)
        {
            _writer.WriteStartElement(function.IsFunctionImport ? XmlConstants.FunctionImport : XmlConstants.Function);
            _writer.WriteAttributeString(XmlConstants.Name, function.Name);

            // Write function ReturnType as attribute if possible.
            bool returnParameterHandled = false;

            if (function.ReturnParameter != null)
            {
                var  returnTypeUsage = function.ReturnParameter.TypeUsage;
                bool collection      = returnTypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType;
                if (collection)
                {
                    Debug.Assert(_schemaVersion >= EntityFrameworkVersions.Version3, "_schemaVersion >= EntityFrameworkVersions.Version3");
                    returnTypeUsage = ((CollectionType)returnTypeUsage.EdmType).TypeUsage;
                }
                if (TypeSemantics.IsPrimitiveType(returnTypeUsage) || TypeSemantics.IsNominalType(returnTypeUsage))
                {
                    string typeName = GetFullName(returnTypeUsage.EdmType);
                    if (collection)
                    {
                        typeName = "Collection(" + typeName + ")";
                    }
                    _writer.WriteAttributeString(XmlConstants.ReturnType, typeName);
                    returnParameterHandled = true;
                }
            }

            if (!_isModel)
            {
                _writer.WriteAttributeString(XmlConstants.AggregateAttribute, GetAttributeValueString(function.AggregateAttribute));
                _writer.WriteAttributeString(XmlConstants.BuiltInAttribute, GetAttributeValueString(function.BuiltInAttribute));
                _writer.WriteAttributeString(XmlConstants.NiladicFunction, GetAttributeValueString(function.NiladicFunctionAttribute));
                _writer.WriteAttributeString(XmlConstants.IsComposable, GetAttributeValueString(function.IsComposableAttribute));
                _writer.WriteAttributeString(XmlConstants.ParameterTypeSemantics, GetAttributeValueString(function.ParameterTypeSemanticsAttribute));
            }
            else if (function.IsFunctionImport && function.IsComposableAttribute)
            {
                Debug.Assert(_schemaVersion >= EntityFrameworkVersions.Version3, "_schemaVersion >= EntityFrameworkVersions.Version3");
                _writer.WriteAttributeString(XmlConstants.IsComposable, GetAttributeValueString(true));
            }

            if (function.StoreFunctionNameAttribute != null)
            {
                _writer.WriteAttributeString(XmlConstants.StoreFunctionName, function.StoreFunctionNameAttribute);
            }

            if (function.CommandTextAttribute != null)
            {
                Debug.Assert(!_isModel, "Serialization of CommandTextAttribute is not supported for CSDL.");
                _writer.WriteAttributeString(XmlConstants.CommandText, function.CommandTextAttribute);
            }

            if (function.Schema != null)
            {
                _writer.WriteAttributeString(XmlConstants.Schema, function.Schema);
            }

            foreach (FunctionParameter parameter in function.Parameters)
            {
                WriteFunctionParameterElement(parameter);
            }

            // Write function ReturnType subelement if needed.
            if (function.ReturnParameter != null && !returnParameterHandled)
            {
                // Handle a TVF in s-space: Collection(RowType)
                if (function.ReturnParameter.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
                {
                    Debug.Assert(_schemaVersion >= EntityFrameworkVersions.Version3 && !_isModel, "_schemaVersion >= EntityFrameworkVersions.Version3 && !_isModel");
                    var elementType = ((CollectionType)function.ReturnParameter.TypeUsage.EdmType).TypeUsage.EdmType;
                    Debug.Assert(elementType.BuiltInTypeKind == BuiltInTypeKind.RowType, "TVF return type is expected to be Collection(RowType)");
                    var rowType = (RowType)elementType;
                    _writer.WriteStartElement(XmlConstants.ReturnType);
                    _writer.WriteStartElement(XmlConstants.CollectionType);
                    WriteTypeElement(rowType);
                    _writer.WriteEndElement();
                    _writer.WriteEndElement();
                    returnParameterHandled = true;
                }
            }

            Debug.Assert(function.ReturnParameter == null || returnParameterHandled, "ReturnParameter was not handled.");
            _writer.WriteEndElement();
        }