示例#1
0
        public void Generate(
            EntityType entityType,
            IEnumerable <EdmProperty> properties,
            EntitySetMapping entitySetMapping,
            MappingFragment entityTypeMappingFragment,
            IList <EdmProperty> propertyPath,
            bool createNewColumn)
        {
            ReadOnlyMetadataCollection <EdmProperty> declaredProperties = entityType.GetRootType().DeclaredProperties;

            foreach (EdmProperty property1 in properties)
            {
                EdmProperty property = property1;
                if (property.IsComplexType && propertyPath.Any <EdmProperty>((Func <EdmProperty, bool>)(p =>
                {
                    if (p.IsComplexType)
                    {
                        return(p.ComplexType == property.ComplexType);
                    }
                    return(false);
                })))
                {
                    throw Error.CircularComplexTypeHierarchy();
                }
                propertyPath.Add(property);
                if (property.IsComplexType)
                {
                    this.Generate(entityType, (IEnumerable <EdmProperty>)property.ComplexType.Properties, entitySetMapping, entityTypeMappingFragment, propertyPath, createNewColumn);
                }
                else
                {
                    EdmProperty edmProperty = entitySetMapping.EntityTypeMappings.SelectMany <EntityTypeMapping, MappingFragment>((Func <EntityTypeMapping, IEnumerable <MappingFragment> >)(etm => (IEnumerable <MappingFragment>)etm.MappingFragments)).SelectMany <MappingFragment, ColumnMappingBuilder>((Func <MappingFragment, IEnumerable <ColumnMappingBuilder> >)(etmf => etmf.ColumnMappings)).Where <ColumnMappingBuilder>((Func <ColumnMappingBuilder, bool>)(pm => pm.PropertyPath.SequenceEqual <EdmProperty>((IEnumerable <EdmProperty>)propertyPath))).Select <ColumnMappingBuilder, EdmProperty>((Func <ColumnMappingBuilder, EdmProperty>)(pm => pm.ColumnProperty)).FirstOrDefault <EdmProperty>();
                    if (edmProperty == null || createNewColumn)
                    {
                        string columnName = string.Join("_", propertyPath.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name)));
                        edmProperty = this.MapTableColumn(property, columnName, !declaredProperties.Contains(propertyPath.First <EdmProperty>()));
                        entityTypeMappingFragment.Table.AddColumn(edmProperty);
                        if (entityType.KeyProperties().Contains <EdmProperty>(property))
                        {
                            entityTypeMappingFragment.Table.AddKeyMember((EdmMember)edmProperty);
                        }
                    }
                    entityTypeMappingFragment.AddColumnMapping(new ColumnMappingBuilder(edmProperty, (IList <EdmProperty>)propertyPath.ToList <EdmProperty>()));
                }
                propertyPath.Remove(property);
            }
        }
示例#2
0
        /// <summary>
        /// Indicates whether the given property name exists on the result.
        /// The result could be indicated by a wrapperCollection, an entitySet or a typeUsage,
        /// any of which could be null.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="wrapperCollection"></param>
        /// <param name="entitySet"></param>
        /// <param name="tu"></param>
        /// <returns></returns>
        internal static bool PropertyIsOnEntity(string propertyName, EntityDataSourceWrapperCollection wrapperCollection, EntitySet entitySet, TypeUsage tu)
        {
            bool propertyIsOnEntity = false;

            if (null != wrapperCollection)
            {
                // check for descriptor
                if (null != wrapperCollection.GetItemProperties(null).Find(propertyName, /*ignoreCase*/ false))
                {
                    propertyIsOnEntity = true;
                }
            }
            if (null != tu)
            {
                ReadOnlyMetadataCollection <EdmMember> members = null;
                switch (tu.EdmType.BuiltInTypeKind)
                {
                case BuiltInTypeKind.RowType:
                    members = ((RowType)(tu.EdmType)).Members;
                    break;

                case BuiltInTypeKind.EntityType:
                    members = ((EntityType)(tu.EdmType)).Members;
                    break;
                }
                if (null != members && members.Contains(propertyName))
                {
                    propertyIsOnEntity = true;
                }
            }
            if (null != entitySet)
            {
                if (((EntityType)(entitySet.ElementType)).Members.Contains(propertyName))
                {
                    propertyIsOnEntity = true;
                }
            }
            return(propertyIsOnEntity);
        }
        private static void GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, DmlSqlGenerator.ExpressionTranslator translator, DbExpression returning, EFOracleProviderManifest providerManifest, EFOracleVersion sqlVersion, bool isUpdate)
        {
            if (returning == null)
            {
                return;
            }
            EntitySetBase target        = ((DbScanExpression)tree.Target.Expression).Target;
            StringBuilder stringBuilder = new StringBuilder(50);

            stringBuilder.Append("declare\n");
            Dictionary <EdmMember, string> dictionary = new Dictionary <EdmMember, string>();

            foreach (EdmMember member in target.ElementType.Members)
            {
                ReadOnlyMetadataCollection <Facet> facets = ((TypeUsage)member.MetadataProperties["TypeUsage"].Value).Facets;
                string empty = string.Empty;
                if (facets.Contains("StoreGeneratedPattern"))
                {
                    string str = facets["StoreGeneratedPattern"].Value.ToString();
                    if (!string.IsNullOrEmpty(str))
                    {
                        if (isUpdate && str.ToUpperInvariant() == "COMPUTED")
                        {
                            dictionary[member] = str;
                        }
                        else if (!isUpdate && (str.ToUpperInvariant() == "COMPUTED" || str.ToUpperInvariant() == "IDENTITY"))
                        {
                            dictionary[member] = str;
                        }
                    }
                }
                if (dictionary.ContainsKey(member))
                {
                    stringBuilder.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    stringBuilder.Append(" ");
                    stringBuilder.Append(SqlGenerator.GetSqlPrimitiveType((DbProviderManifest)providerManifest, sqlVersion, member.TypeUsage));
                    stringBuilder.Append(";\n");
                }
            }
            stringBuilder.Append("begin\n");
            commandText.Insert(0, stringBuilder.ToString());
            OracleParameter parameter = translator.CreateParameter(OracleDbType.RefCursor, ParameterDirection.Output);

            commandText.Append("returning\n");
            string str1 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str1);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str1 = ", ";
                }
            }
            commandText.Append(" into\n");
            string str2 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str2);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str2 = ", ";
                }
            }
            commandText.Append(";\n");
            commandText.Append("open ");
            commandText.Append(parameter.ParameterName);
            commandText.Append(" for select\n");
            string str3 = string.Empty;

            foreach (EdmMember member in target.ElementType.Members)
            {
                if (dictionary.ContainsKey(member))
                {
                    commandText.Append(str3);
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    commandText.Append(" as ");
                    commandText.Append(DmlSqlGenerator.GenerateMemberTSql(member));
                    str3 = ", ";
                }
            }
            commandText.Append(" from dual;\n");
            commandText.Append("end;");
        }
示例#4
0
        internal StateManagerTypeMetadata(EdmType edmType, ObjectTypeMapping mapping)
        {
            Debug.Assert(null != edmType, "null EdmType");
            Debug.Assert(Helper.IsEntityType(edmType) ||
                         Helper.IsComplexType(edmType),
                         "not Complex or EntityType");
            Debug.Assert(Object.ReferenceEquals(mapping, null) ||
                         Object.ReferenceEquals(mapping.EdmType, edmType),
                         "different EdmType instance");

            _typeUsage = TypeUsage.Create(edmType);
            _recordInfo = new DataRecordInfo(_typeUsage);
            _ocObjectMap = mapping;

            ReadOnlyMetadataCollection<EdmProperty> members = TypeHelpers.GetProperties(edmType);
            _members = new StateManagerMemberMetadata[members.Count];
            _objectNameToOrdinal = new Dictionary<string, int>(members.Count);
            _cLayerNameToOrdinal = new Dictionary<string, int>(members.Count);

            ReadOnlyMetadataCollection<EdmMember> keyMembers = null;
            if (Helper.IsEntityType(edmType))
            {
                keyMembers = ((EntityType)edmType).KeyMembers;
            }

            for (int i = 0; i < _members.Length; ++i)
            {
                EdmProperty member = members[i];

                ObjectPropertyMapping memberMap = null;
                if (null != mapping)
                {
                    memberMap = mapping.GetPropertyMap(member.Name);
                    if (null != memberMap)
                    {
                        _objectNameToOrdinal.Add(memberMap.ClrProperty.Name, i); // olayer name
                    }
                }
                _cLayerNameToOrdinal.Add(member.Name, i); // clayer name

                // Determine whether this member is part of the identity of the entity.
                _members[i] = new StateManagerMemberMetadata(memberMap, member, ((null != keyMembers) && keyMembers.Contains(member)));
            }
        }
        internal StateManagerTypeMetadata(EdmType edmType, ObjectTypeMapping mapping)
        {
            this._typeUsage  = TypeUsage.Create(edmType);
            this._recordInfo = new DataRecordInfo(this._typeUsage);
            ReadOnlyMetadataCollection <EdmProperty> properties = TypeHelpers.GetProperties(edmType);

            this._members             = new StateManagerMemberMetadata[properties.Count];
            this._objectNameToOrdinal = new Dictionary <string, int>(properties.Count);
            this._cLayerNameToOrdinal = new Dictionary <string, int>(properties.Count);
            ReadOnlyMetadataCollection <EdmMember> metadataCollection = (ReadOnlyMetadataCollection <EdmMember>)null;

            if (Helper.IsEntityType(edmType))
            {
                metadataCollection = ((EntityTypeBase)edmType).KeyMembers;
            }
            for (int index = 0; index < this._members.Length; ++index)
            {
                EdmProperty           memberMetadata = properties[index];
                ObjectPropertyMapping memberMap      = (ObjectPropertyMapping)null;
                if (mapping != null)
                {
                    memberMap = mapping.GetPropertyMap(memberMetadata.Name);
                    if (memberMap != null)
                    {
                        this._objectNameToOrdinal.Add(memberMap.ClrProperty.Name, index);
                    }
                }
                this._cLayerNameToOrdinal.Add(memberMetadata.Name, index);
                this._members[index] = new StateManagerMemberMetadata(memberMap, memberMetadata, metadataCollection != null && metadataCollection.Contains((EdmMember)memberMetadata));
            }
        }