protected virtual string GetCompositeIndexNameWithSchema(CompositeIndexAttribute compositeIndex, ModelDefinition modelDef)
 {
     return(compositeIndex.Name ?? GetIndexName(compositeIndex.Unique,
                                                (modelDef.IsInSchema ?
                                                 modelDef.Schema + "_" + GetQuotedTableName(modelDef) :
                                                 GetQuotedTableName(modelDef)).SafeVarName(),
                                                string.Join("_", compositeIndex.FieldNames.ToArray())));
 }
Ejemplo n.º 2
0
        /// <summary> Write a CompositeIndex XML Element from attributes in a member. </summary>
        public virtual void WriteCompositeIndex(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, CompositeIndexAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "composite-index" );
            // Attribute: <class>
            writer.WriteAttributeString("class", attribute.Class==null ? DefaultHelper.Get_CompositeIndex_Class_DefaultValue(member) : GetAttributeValue(attribute.Class, mappedClass));

            WriteUserDefinedContent(writer, member, null, attribute);

            System.Collections.ArrayList memberAttribs = GetSortedAttributes(member);
            int attribPos; // Find the position of the CompositeIndexAttribute (its <sub-element>s must be after it)
            for(attribPos=0; attribPos<memberAttribs.Count; attribPos++)
                if( memberAttribs[attribPos] is CompositeIndexAttribute
                    && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position )
                    break; // found
            int i = attribPos + 1;

            // Element: <key-property>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(KeyPropertyAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is CompositeIndexAttribute )
                        break; // Following attributes are for this CompositeIndex
                    if( memberAttrib is KeyPropertyAttribute )
                        WriteKeyProperty(writer, member, memberAttrib as KeyPropertyAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(KeyPropertyAttribute), attribute);
            // Element: <key-many-to-one>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(KeyManyToOneAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is CompositeIndexAttribute )
                        break; // Following attributes are for this CompositeIndex
                    if( memberAttrib is KeyManyToOneAttribute )
                        WriteKeyManyToOne(writer, member, memberAttrib as KeyManyToOneAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(KeyManyToOneAttribute), attribute);

            writer.WriteEndElement();
        }
 protected virtual string GetCompositeIndexName(CompositeIndexAttribute compositeIndex, ModelDefinition modelDef)
 {
     return(compositeIndex.Name ?? GetIndexName(compositeIndex.Unique, modelDef.ModelName.SafeVarName(),
                                                string.Join("_", compositeIndex.FieldNames.ToArray())));
 }