public override void Initialize()
        {
            var column = PropertySource.Attribute("column") ?? PropertySource.Attribute("name");
            var name   = PropertySource.Attribute("name") ?? column;

            KeyName = column.Value;
            Name    = name.Value;

            var type            = PropertySource.Attribute("type").Value;
            var lengthAttribute = PropertySource.Attribute("length");
            int?length          = null;

            if (lengthAttribute != null)
            {
                int lengthInt;
                if (Int32.TryParse(lengthAttribute.Value, out lengthInt))
                {
                    length = lengthInt;
                }
            }

            SystemType = NHibernateUtilities.FromNHibernateType(type, length);
        }
Example #2
0
        public override void Initialize()
        {
            // ReSharper disable PossibleNullReferenceException
            var name   = PropertySource.Attribute("name").Value;
            var type   = PropertySource.Attribute("type").Value;
            var column = PropertySource.Attribute("column").Value;

            var lengthAttribute = PropertySource.Attribute("length");
            int?length          = null;

            if (lengthAttribute != null)
            {
                int lengthInt;
                if (Int32.TryParse(lengthAttribute.Value, out lengthInt))
                {
                    length = lengthInt;
                }
            }

            KeyName = _safeName = column;
            Name    = name;

            GetterAccess = "public";
            SetterAccess = "public";

            var notnull = PropertySource.Attribute(NHibernateUtilities.NotNull);

            if (notnull == null)
            {
                IsNullable = false;
            }
            else
            {
                bool notnullValue;
                IsNullable = Boolean.TryParse(notnull.Value, out notnullValue) && !notnullValue;
            }

            SystemType = IsNullable
                ? NHibernateUtilities.FromNHibernateNullableType(type, length)
                : NHibernateUtilities.FromNHibernateType(type, length);

            ExtendedProperties.Add(NHibernateUtilities.NHibernateType, type);

            var generator = PropertySource.Descendant("generator", ((NHibernateEntity)Entity).XmlNamespace);

            if (generator != null)
            {
                ExtendedProperties.Add(NHibernateUtilities.GeneratorClass, generator.Attribute("class").Value);
            }

            var customAttributes = PropertySource
                                   .Attributes()
                                   .Where(a => !DefaultAttributes.Contains(a.Name.ToString()));

            foreach (var customAttribute in customAttributes)
            {
                // Special case, always preserve length from DB.
                if (customAttribute.Name.ToString() == "length")
                {
                    continue;
                }

                ExtendedProperties.Add(customAttribute.Name.ToString(), customAttribute.Value);
            }
            // ReSharper restore PossibleNullReferenceException
        }