Ejemplo n.º 1
0
            public override Column VisitColumn(Column column)
            {
                if (column == null)
                    return null;

                return new Column(column.Type)
                           {
                               Name = column.Name,
                               Member = column.Member,
                               Storage = column.Storage,
                               AccessModifier = column.AccessModifier,
                               Modifier = column.Modifier,
                               AutoSync = column.AutoSync,
                               DbType = column.DbType,
                               IsReadOnly = column.IsReadOnly,
                               IsPrimaryKey = column.IsPrimaryKey,
                               IsDbGenerated = column.IsDbGenerated,
                               CanBeNull = column.CanBeNull,
                               UpdateCheck = column.UpdateCheck,
                               IsDiscriminator = column.IsDiscriminator,
                               Expression = column.Expression,
                               IsVersion = column.IsVersion,
                               IsDelayLoaded = column.IsDelayLoaded
                           };
            }
            public override Column VisitColumn(Column column)
            {
                if (column == null)
                    return null;

                if (column.Storage == ("_" + column.Member))
                    column.Storage = null;

                if (column.Name == column.Member)
                    column.Member = null;

                if (column.AccessModifier.HasValue && column.AccessModifier.Value == AccessModifier.Public)
                    column.AccessModifier = null;

                if (column.AutoSync.HasValue && column.AutoSync == AutoSync.OnInsert
                    && column.IsDbGenerated == true && column.IsPrimaryKey == true)
                    column.AutoSync = null;
                else if (column.AutoSync.HasValue && column.AutoSync == AutoSync.Always
                    && column.IsDbGenerated == true)
                    column.AutoSync = null;
                else if (column.AutoSync.HasValue && column.AutoSync == AutoSync.Never
                    && column.IsVersion != true && column.IsDbGenerated != true)
                    column.AutoSync = null;

                if (column.IsReadOnly == false)
                    column.IsReadOnly = null;

                if (!string.IsNullOrEmpty(column.Expression) || (column.IsVersion == true))
                {
                    if (column.IsDbGenerated == true)
                        column.IsDbGenerated = null;
                }
                else if (column.IsDbGenerated == false)
                {
                    column.IsDbGenerated = null;
                }

                if (column.IsPrimaryKey == false)
                    column.IsPrimaryKey = null;

                if (column.IsDiscriminator == false)
                    column.IsDiscriminator = null;

                if (column.IsVersion == false)
                    column.IsVersion = null;

                if (column.IsDelayLoaded == false)
                    column.IsDelayLoaded = null;

                return column;
            }
            public override Column VisitColumn(Column column)
            {
                if (column == null)
                    return null;

                if ((column.Name == null) && (column.Member != null))
                    column.Name = column.Member;

                if ((column.Member == null) && (column.Name != null))
                    column.Member = column.Name;

                if (column.Storage == null)
                    column.Storage = "_" + column.Member;

                if (!column.AccessModifier.HasValue)
                    column.AccessModifier = 0;

                if (!column.IsPrimaryKey.HasValue)
                    column.IsPrimaryKey = false;

                if (!column.IsDiscriminator.HasValue)
                    column.IsDiscriminator = false;

                if (!column.IsVersion.HasValue)
                    column.IsVersion = false;

                if (!column.IsDelayLoaded.HasValue)
                    column.IsDelayLoaded = false;

                if (!column.IsDbGenerated.HasValue)
                    column.IsDbGenerated = !string.IsNullOrEmpty(column.Expression) || (column.IsVersion == true);

                if (!column.IsReadOnly.HasValue)
                    column.IsReadOnly = false;

                if (!column.AutoSync.HasValue)
                {
                    if ((column.IsDbGenerated == true) && (column.IsPrimaryKey == true))
                        column.AutoSync = (AutoSync) 3;
                    else if (column.IsDbGenerated == true)
                        column.AutoSync = (AutoSync) 1;
                    else
                        column.AutoSync = (AutoSync) 2;
                }

                if (column.IsReadOnly == true)
                    column.UpdateCheck = (UpdateCheck) 1;

                return column;
            }
Ejemplo n.º 4
0
 public bool TryFindColumn(string columnName, bool includeSubtypes, out Column column)
 {
     column = Find(this, columnName, includeSubtypes);
     return (column != null);
 }
Ejemplo n.º 5
0
        public Association GetForeignKeyAssociation(Column c)
        {
            foreach (Association a in Associations)
                if (a.IsForeignKey == true && a.ThisKey.Equals(c.Member))
                    return a;

            return null;
        }
Ejemplo n.º 6
0
        private void CreateView(ViewSchema viewSchema)
        {
            Table table;

            if (Database.Tables.Contains(viewSchema.FullName))
            {
                table = Database.Tables[viewSchema.FullName];
            }
            else
            {
                Type type = new Type(ToClassName(viewSchema.Name));
                table = new Table(viewSchema.FullName, type);
                Database.Tables.Add(table);
            }

            if (string.IsNullOrEmpty(table.Type.Name))
                table.Type.Name = ToClassName(viewSchema.Name);

            if (string.IsNullOrEmpty(table.Member))
                table.Member = table.Type.Name;

            foreach (ViewColumnSchema columnSchema in viewSchema.Columns)
            {
                Column column;

                if (table.Type.Columns.Contains(columnSchema.Name))
                {
                    column = table.Type.Columns[columnSchema.Name];
                }
                else
                {
                    column = new Column(GetSystemType(columnSchema));
                    column.Name = columnSchema.Name;
                    table.Type.Columns.Add(column);
                }

                PopulateColumn(column, columnSchema, table.Type.Name);
            }

            table.Type.Columns.IsProcessed = true;
            table.Type.Associations.IsProcessed = true;
            table.IsProcessed = true;
        }
Ejemplo n.º 7
0
        private void CreateResult(Function function, CommandResultSchema commandResultSchema, string defaultName, int index)
        {
            string name = defaultName;
            Type result;

            if (function.Types.Contains(name))
            {
                result = function.Types[name];
            }
            else if (function.Types.Count >= index + 1)
            {
                result = function.Types[index];
            }
            else
            {
                result = new Type(ToClassName(name));
                function.Types.Add(result);
            }

            if (result.IsProcessed)
                return;

            // ElementType/@Name safe attribute
            if (string.IsNullOrEmpty(result.Name))
                result.Name = ToClassName(name);

            foreach (CommandResultColumnSchema c in commandResultSchema.Columns)
            {
                Column column;

                if (result.Columns.Contains(c.Name))
                {
                    column = result.Columns[c.Name];
                }
                else
                {
                    column = new Column(GetSystemType(c));
                    column.Name = c.Name;
                    result.Columns.Add(column);
                }

                if (!column.IsProcessed)
                    PopulateColumn(column, c, result.Name);
            }

            result.IsProcessed = true;
        }
Ejemplo n.º 8
0
        private void CreateColumns(Table table, TableSchema tableSchema)
        {
            foreach (ColumnSchema columnSchema in tableSchema.Columns)
            {
                // skip unsupported type
                if (Settings.IsUnsupportedDbType(columnSchema))
                {
                    Debug.WriteLine(string.Format("Skipping column '{0}' because it has an unsupported db type '{1}'.", columnSchema.Name, columnSchema.NativeType));
                    Trace.WriteLine(string.Format("Skipping column '{0}' because it has an unsupported db type '{1}'.", columnSchema.Name, columnSchema.NativeType));
                    continue;
                }

                Column column;
                bool isNew = !table.Type.TryFindColumn(columnSchema.Name, true, out column);

                if (isNew)
                {
                    column = new Column(GetColumnType(columnSchema));
                    column.Name = columnSchema.Name;
                    table.Type.Columns.Add(column);
                }

                PopulateColumn(column, columnSchema, table.Type.Name);

                if (column.IsPrimaryKey != true)
                    column.IsPrimaryKey = columnSchema.IsPrimaryKeyMember;
            }

            table.Type.Columns.IsProcessed = true;
        }
Ejemplo n.º 9
0
        private void PopulateColumn(Column column, DataObjectBase columnSchema, string className)
        {
            bool canUpdateType = string.IsNullOrEmpty(column.Type)
                || column.Type.StartsWith("System.")
                || IsOrWasEnumAssociation(columnSchema);

            if (canUpdateType)
                column.Type = GetColumnType(columnSchema);

            if (!PropertyNames.ContainsKey(className))
                PropertyNames.Add(className, new List<string>());

            //Column/@Member is edit safe if it is NullOrEmpty.
            // However, if the column starts with a digit, then we ARE going to update it.
            if (string.IsNullOrEmpty(column.Member) || CleanNumberPrefix.IsMatch(column.Member))
            {
                column.Member = ToPropertyName(className, columnSchema.Name);
                column.Storage = CommonUtility.GetFieldName(column.Member);
            }
            else
            {
                PropertyNames[className].Add(column.Member);
            }

            if (columnSchema.NativeType.Equals("text", StringComparison.OrdinalIgnoreCase)
                || columnSchema.NativeType.Equals("ntext", StringComparison.OrdinalIgnoreCase)
                || columnSchema.NativeType.Equals("xml", StringComparison.OrdinalIgnoreCase)
                || columnSchema.NativeType.Equals("binary", StringComparison.OrdinalIgnoreCase)
                || columnSchema.NativeType.Equals("image", StringComparison.OrdinalIgnoreCase))
                column.UpdateCheck = UpdateCheck.Never;

            column.DbType = GetDbType(columnSchema);
            column.CanBeNull = columnSchema.AllowDBNull;
            column.IsVersion = IsRowVersion(columnSchema);

            if (!column.IsDbGenerated.HasValue)
                column.IsDbGenerated = IsDbGenerated(columnSchema);

            column.IsProcessed = true;
        }
Ejemplo n.º 10
0
            public override Column VisitColumn(Column column)
            {
                if (column == null)
                    return null;

                writer.WriteStartElement("Column");

                if (column.Name != null)
                    writer.WriteAttributeString("Name", column.Name);

                if (column.Member != null)
                    writer.WriteAttributeString("Member", column.Member);

                if (column.Storage != null)
                    writer.WriteAttributeString("Storage", column.Storage);

                if (column.AccessModifier.HasValue)
                    writer.WriteAttributeString("AccessModifier", column.AccessModifier.ToString());

                if (column.Modifier.HasValue)
                    writer.WriteAttributeString("Modifier", column.Modifier.ToString());

                if (column.AutoSync.HasValue)
                    writer.WriteAttributeString("AutoSync", column.AutoSync.ToString());

                if (column.Type != null)
                    writer.WriteAttributeString("Type", column.Type);

                if (column.DbType != null)
                    writer.WriteAttributeString("DbType", column.DbType);

                if (column.IsReadOnly.HasValue)
                    writer.WriteAttributeString("IsReadOnly", ToXmlBooleanString(column.IsReadOnly));

                if (column.IsPrimaryKey.HasValue)
                    writer.WriteAttributeString("IsPrimaryKey", ToXmlBooleanString(column.IsPrimaryKey));

                if (column.IsDbGenerated.HasValue)
                    writer.WriteAttributeString("IsDbGenerated", ToXmlBooleanString(column.IsDbGenerated));

                if (column.CanBeNull.HasValue)
                    writer.WriteAttributeString("CanBeNull", ToXmlBooleanString(column.CanBeNull));

                if (column.UpdateCheck.HasValue)
                    writer.WriteAttributeString("UpdateCheck", column.UpdateCheck.ToString());

                if (column.IsDiscriminator.HasValue)
                    writer.WriteAttributeString("IsDiscriminator", ToXmlBooleanString(column.IsDiscriminator));

                if (column.Expression != null)
                    writer.WriteAttributeString("Expression", column.Expression);

                if (column.IsVersion.HasValue)
                    writer.WriteAttributeString("IsVersion", ToXmlBooleanString(column.IsVersion));

                if (column.IsDelayLoaded.HasValue)
                    writer.WriteAttributeString("IsDelayLoaded", ToXmlBooleanString(column.IsDelayLoaded));

                writer.WriteEndElement();
                return column;
            }
Ejemplo n.º 11
0
            private static Column ReadColumn(XmlTextReader reader)
            {
                ValidateAttributes(reader, new[]
                                               {
                                                   "Name", "Type", "Member", "Storage", "AccessModifier", "Modifier",
                                                   "AutoSync", "IsDbGenerated", "IsReadOnly", "IsPrimaryKey",
                                                   "CanBeNull", "UpdateCheck", "Expression", "IsDiscriminator",
                                                   "IsVersion", "IsDelayLoaded",
                                                   "DbType"
                                               });

                var column = new Column("")
                                 {
                                     Name = reader.GetAttribute("Name"),
                                     Member = reader.GetAttribute("Member"),
                                     Storage = reader.GetAttribute("Storage")
                                 };

                if ((column.Name == null) && (column.Member == null))
                    throw Error.SchemaOrRequirementViolation("Column", "Name", "Member", reader.LineNumber);

                string attribute = reader.GetAttribute("AccessModifier");
                try
                {
                    if (attribute == null)
                        column.AccessModifier = null;
                    else
                        column.AccessModifier = (AccessModifier) Enum.Parse(typeof (AccessModifier), attribute, true);

                    attribute = reader.GetAttribute("Modifier");
                    if (attribute == null)
                        column.Modifier = null;
                    else
                        column.Modifier = (MemberModifier) Enum.Parse(typeof (MemberModifier), attribute, true);

                    attribute = reader.GetAttribute("AutoSync");
                    if (attribute == null)
                        column.AutoSync = null;
                    else
                        column.AutoSync = (AutoSync) Enum.Parse(typeof (AutoSync), attribute, true);

                    attribute = reader.GetAttribute("IsDbGenerated");
                    column.IsDbGenerated = (attribute == null) ? null : new bool?(bool.Parse(attribute));

                    attribute = reader.GetAttribute("IsReadOnly");
                    column.IsReadOnly = (attribute == null) ? null : new bool?(bool.Parse(attribute));

                    attribute = reader.GetAttribute("IsPrimaryKey");
                    column.IsPrimaryKey = (attribute == null) ? null : new bool?(bool.Parse(attribute));

                    attribute = reader.GetAttribute("CanBeNull");
                    column.CanBeNull = (attribute == null) ? null : new bool?(bool.Parse(attribute));

                    attribute = reader.GetAttribute("UpdateCheck");
                    if (attribute == null)
                        column.UpdateCheck = null;
                    else
                        column.UpdateCheck = (UpdateCheck) Enum.Parse(typeof (UpdateCheck), attribute, true);

                    attribute = reader.GetAttribute("IsDiscriminator");
                    column.IsDiscriminator = (attribute == null) ? null : new bool?(bool.Parse(attribute));
                    column.Expression = reader.GetAttribute("Expression");

                    attribute = reader.GetAttribute("IsVersion");
                    column.IsVersion = (attribute == null) ? null : new bool?(bool.Parse(attribute));

                    attribute = reader.GetAttribute("IsDelayLoaded");
                    column.IsDelayLoaded = (attribute == null) ? null : new bool?(bool.Parse(attribute));
                }
                catch (FormatException)
                {
                    throw Error.InvalidBooleanAttributeValueViolation(attribute, reader.LineNumber);
                }
                catch (ArgumentException)
                {
                    throw Error.InvalidEnumAttributeValueViolation(attribute, reader.LineNumber);
                }

                string typeAttribute = reader.GetAttribute("Type");
                if (typeAttribute == null)
                    throw Error.RequiredAttributeMissingViolation("Type", reader.LineNumber);

                column.Type = typeAttribute;
                column.DbType = reader.GetAttribute("DbType");
                AssertEmptyElement(reader);
                return column;
            }