Ejemplo n.º 1
0
        /// <summary>
        ///     Returns list of MappingFunctionImportScalarProperty for each Property from the ReturnType of the FunctionImport
        /// </summary>
        internal IList <MappingFunctionImportScalarProperty> GetScalarProperties()
        {
            var mappingScalarProperties = new List <MappingFunctionImportScalarProperty>();
            var fi = FunctionImportMapping.FunctionImportName.Target;

            Debug.Assert(fi != null, "No binding to FunctionImport found");
            if (fi != null)
            {
                // first get the ReturnType of the FunctionImport (should be either EntityType or ComplexType)
                ComplexType complexType = null;
                EntityType  entityType  = null;
                if (fi.IsReturnTypeEntityType)
                {
                    entityType = fi.ReturnTypeAsEntityType.Target;
                }
                else if (fi.IsReturnTypeComplexType &&
                         fi.ReturnTypeAsComplexType.Target != null)
                {
                    complexType = fi.ReturnTypeAsComplexType.Target;
                }

                Debug.Assert(entityType != null || complexType != null, "Couldn't find FunctionImport return type");
                if (entityType != null ||
                    complexType != null)
                {
                    // check wether we have corresponding TypeMapping inside the FunctionImportMapping
                    FunctionImportTypeMapping typeMapping = null;
                    if (FunctionImportMapping.ResultMapping != null)
                    {
                        typeMapping = entityType != null
                                          ? FunctionImportMapping.ResultMapping.FindTypeMapping(entityType)
                                          : FunctionImportMapping.ResultMapping.FindTypeMapping(complexType);
                    }

                    var properties = entityType != null?entityType.Properties() : complexType.Properties();

                    foreach (var property in properties)
                    {
                        if (typeMapping != null)
                        {
                            // check whether we already have ScalarProperty for this Property
                            var scalarProperty = typeMapping.FindScalarProperty(property);
                            if (scalarProperty != null)
                            {
                                // add existing ScalarProperty to the list
                                mappingScalarProperties.Add(new MappingFunctionImportScalarProperty(_context, scalarProperty, this));
                                continue;
                            }
                        }
                        // if not, add a dummy node
                        mappingScalarProperties.Add(new MappingFunctionImportScalarProperty(_context, property, this));
                    }
                }
            }
            return(mappingScalarProperties);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates new ScalarProperty inside specified FunctionImportTypeMapping
        /// </summary>
        /// <param name="typeMapping"></param>
        /// <param name="property">Valid c-side Property (either from EntityType or ComplexType)</param>
        /// <param name="columnName"></param>
        internal CreateFunctionImportScalarPropertyCommand(FunctionImportTypeMapping typeMapping, Property property, string columnName)
        {
            CommandValidation.ValidateFunctionImportTypeMapping(typeMapping);
            CommandValidation.ValidateConceptualProperty(property);
            ValidateString(columnName);

            _typeMapping = typeMapping;
            _property    = property;
            _columnName  = columnName;
        }
Ejemplo n.º 3
0
        protected override void ProcessPreReqCommands()
        {
            if (_typeMapping == null)
            {
                var prereq = GetPreReqCommand(CreateFunctionImportTypeMappingCommand.PrereqId) as CreateFunctionImportTypeMappingCommand;
                if (prereq != null)
                {
                    _typeMapping = prereq.TypeMapping;
                }

                Debug.Assert(_typeMapping != null, "We didn't get good FunctionImportTypeMapping out of the prereq command");
            }
        }
Ejemplo n.º 4
0
 internal static void ValidateFunctionImportTypeMapping(FunctionImportTypeMapping typeMapping)
 {
     ValidateEFElement(typeMapping);
 }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // safety check, this should never be hit
            if ((_entityType == null && _complexType == null) ||
                _functionImportMapping == null)
            {
                throw new InvalidOperationException(
                          "InvokeInternal is called when _entityType or _complexType or _functionImportMapping is null.");
            }

            if (_functionImportMapping.ResultMapping == null)
            {
                _functionImportMapping.ResultMapping = new ResultMapping(_functionImportMapping, null);
                XmlModelHelper.NormalizeAndResolve(_functionImportMapping.ResultMapping);
            }

            // first check if we already have one (if found we'll simply return it)
            _createdTypeMapping = _entityType != null
                                      ? _functionImportMapping.ResultMapping.FindTypeMapping(_entityType)
                                      : _functionImportMapping.ResultMapping.FindTypeMapping(_complexType);

            if (_createdTypeMapping == null)
            {
                if (_entityType != null)
                {
                    _createdTypeMapping = new FunctionImportEntityTypeMapping(_functionImportMapping.ResultMapping, null);
                    _createdTypeMapping.TypeName.SetRefName(_entityType);
                }
                else
                {
                    _createdTypeMapping = new FunctionImportComplexTypeMapping(_functionImportMapping.ResultMapping, null);
                    _createdTypeMapping.TypeName.SetRefName(_complexType);
                }

                XmlModelHelper.NormalizeAndResolve(_createdTypeMapping);
                _functionImportMapping.ResultMapping.AddTypeMapping(_createdTypeMapping);
            }

            if (_createDefaultScalarProperties && _createdTypeMapping != null)
            {
                IEnumerable <Property> properties = null;

                if (_entityType != null)
                {
                    properties = _entityType.Properties();
                }
                else if (_complexType != null)
                {
                    properties = _complexType.Properties();
                }

                if (properties != null)
                {
                    foreach (var prop in properties)
                    {
                        // Skip if the property is a Complex Property or if we already have the Scalar Property in the type mapping.
                        if ((prop is ComplexConceptualProperty) == false &&
                            _createdTypeMapping.FindScalarProperty(prop) == null)
                        {
                            var columnName = (_mapPropertyNameToColumnName != null &&
                                              _mapPropertyNameToColumnName.ContainsKey(prop.DisplayName)
                                                  ? _mapPropertyNameToColumnName[prop.DisplayName]
                                                  : prop.DisplayName);
                            CommandProcessor.InvokeSingleCommand(
                                cpc, new CreateFunctionImportScalarPropertyCommand(_createdTypeMapping, prop, columnName));
                        }
                    }
                }
            }
        }