Ejemplo n.º 1
0
        public void Ctor()
        {
            var c = new ColumnAttribute();

            Assert.AreEqual(AutoSync.Default, c.AutoSync);
            Assert.AreEqual(true, c.CanBeNull);
            Assert.AreEqual(null, c.DbType);
            Assert.AreEqual(null, c.Expression);
            Assert.AreEqual(false, c.IsDbGenerated);
            Assert.AreEqual(false, c.IsDiscriminator);
            Assert.AreEqual(false, c.IsVersion);
            Assert.AreEqual(UpdateCheck.Always, c.UpdateCheck);
            Assert.AreEqual(false, c.IsPrimaryKey);
            Assert.AreEqual(null, c.Name);
            Assert.AreEqual(null, c.Storage);
            Assert.AreEqual(c.GetType(), c.TypeId);
        }
Ejemplo n.º 2
0
        /// <summary> Write a Column XML Element from attributes in a member. </summary>
        public virtual void WriteColumn(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ColumnAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "column" );
            // Attribute: <name>
            writer.WriteAttributeString("name", attribute.Name==null ? DefaultHelper.Get_Column_Name_DefaultValue(member) : GetAttributeValue(attribute.Name, mappedClass));
            // Attribute: <length>
            if(attribute.Length != -1)
            writer.WriteAttributeString("length", attribute.Length.ToString());
            // Attribute: <precision>
            if(attribute.Precision != -1)
            writer.WriteAttributeString("precision", attribute.Precision.ToString());
            // Attribute: <scale>
            if(attribute.Scale != -1)
            writer.WriteAttributeString("scale", attribute.Scale.ToString());
            // Attribute: <not-null>
            if( attribute.NotNullSpecified )
            writer.WriteAttributeString("not-null", attribute.NotNull ? "true" : "false");
            // Attribute: <unique>
            if( attribute.UniqueSpecified )
            writer.WriteAttributeString("unique", attribute.Unique ? "true" : "false");
            // Attribute: <unique-key>
            if(attribute.UniqueKey != null)
            writer.WriteAttributeString("unique-key", GetAttributeValue(attribute.UniqueKey, mappedClass));
            // Attribute: <sql-type>
            if(attribute.SqlType != null)
            writer.WriteAttributeString("sql-type", GetAttributeValue(attribute.SqlType, mappedClass));
            // Attribute: <index>
            if(attribute.Index != null)
            writer.WriteAttributeString("index", GetAttributeValue(attribute.Index, mappedClass));
            // Attribute: <check>
            if(attribute.Check != null)
            writer.WriteAttributeString("check", GetAttributeValue(attribute.Check, mappedClass));
            // Attribute: <default>
            if(attribute.Default != null)
            writer.WriteAttributeString("default", GetAttributeValue(attribute.Default, mappedClass));

            WriteUserDefinedContent(writer, member, null, attribute);

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

            // Element: <comment>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(CommentAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is ColumnAttribute )
                        break; // Following attributes are for this Column
                    if( memberAttrib is CommentAttribute )
                        WriteComment(writer, member, memberAttrib as CommentAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(CommentAttribute), attribute);

            writer.WriteEndElement();
        }