Пример #1
0
        internal static XElement GetSimplePropertyHbmXml(ColumnMetadata entry, string xElementName)
        {
            if (entry == null)
                return null;
            if (string.IsNullOrWhiteSpace(xElementName))
                xElementName = Globals.HbmXmlNames.PROPERTY;
            if (string.IsNullOrWhiteSpace(entry.data_type) &&
                Sorting.DbContainers.AllColumns.Data.Any(
                    x => string.Equals(x.column_name, entry.constraint_name, Sorting.C)))
            {
                var acEntry =
                    Sorting.DbContainers.AllColumns.Data.First(
                        x => string.Equals(x.column_name, entry.constraint_name, Sorting.C));
                entry.CopyFrom(acEntry);
            }
            else
            {
                entry.CopyFrom(Sorting.GetFromAllColumnMetadata(entry));
            }

            var simplePropName = Compose.PropertyName(entry.column_name);
            var simplePropColumn = Util.Etc.ExtractLastWholeWord(entry.column_name, null);

            var simplePropDataType = Globals.HbmXmlNames.ANSI_STRING;

            if (!Util.Lexicon.DotNet2HbmTypes.ContainsKey(string.Format("{0}", entry.data_type)) &&
                !Util.Lexicon.Mssql2HbmTypes.ContainsKey(string.Format("{0}", entry.data_type)))
            {
                Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss.ffff} '{1}' has no matching type in the Lexicon [{2}].",
                    DateTime.Now,
                    entry.data_type, entry.ToJsonString());
            }
            else
            {
                simplePropDataType = entry.data_type.StartsWith("System.")
                    ? Util.Lexicon.DotNet2HbmTypes[entry.data_type]
                    : Util.Lexicon.Mssql2HbmTypes[entry.data_type];
            }

            var simplePropLen = simplePropDataType == Globals.HbmXmlNames.ANSI_STRING
                ? entry.string_length == null || entry.string_length <= 0 ? Globals.MSSQL_MAX_VARCHAR : entry.string_length
                : null;

            if (simplePropDataType == typeof (Boolean).Name)
            {
                if (simplePropName.StartsWith(Util.NfTypeName.DefaultNamePrefix))
                    simplePropName = simplePropName.Remove(0, Util.NfTypeName.DefaultNamePrefix.Length);
                simplePropName = "Is" + simplePropName;
            }

            return XeFactory.PropertyNode(xElementName, simplePropName, simplePropColumn,
                simplePropDataType, simplePropLen.ToString(), entry.is_nullable.HasValue && entry.is_nullable == true,
                entry.ToJsonString());
        }
Пример #2
0
        internal static void GetSimpleId(ColumnMetadata pkId, XElement classXe)
        {
            pkId.CopyFrom(Sorting.GetFromAllColumnMetadata(pkId));
            var fullColumnName = pkId.column_name;

            Compose.ValidSplit(fullColumnName, 3);
            var columnName = Util.Etc.ExtractLastWholeWord(fullColumnName, null);
            const string propertyName = Globals.HbmXmlNames.ID;
            var type = Util.Lexicon.Mssql2HbmTypes[(pkId.data_type)];
            var length = pkId.string_length ?? Globals.MSSQL_MAX_VARCHAR;
            XElement idXe;
            //don't let the '-1' from the database make it to the hbm.xml's
            if (string.Equals(type, Globals.HbmXmlNames.ANSI_STRING))
            {
                if (length <= 0)
                    length = Globals.MSSQL_MAX_VARCHAR;
                idXe = XeFactory.IdNode(propertyName, columnName, type,
                    length.ToString(CultureInfo.InvariantCulture),pkId.ToJsonString());
            }
            else
            {
                idXe = XeFactory.IdNode(propertyName, columnName, type, pkId.ToJsonString());
            }

            //simple split of assigned or is_identity
            XElement generatorXe;
            if (pkId.is_auto_increment.HasValue && pkId.is_auto_increment.Value)
            {
                generatorXe = XeFactory.GeneratorId(Globals.HbmXmlNames.IDENTITY);
            }
            else
            {
                generatorXe = XeFactory.GeneratorId(Globals.HbmXmlNames.ASSIGNED);
            }
            idXe.Add(generatorXe);
            classXe.Add(idXe);
        }