Esempio n. 1
0
        public static object ColumnasPorTabla(string valor, params object[] parametros)
        {
            using (ispDB db = new ispDB())
            {
                LinqToDB.SchemaProvider.GetSchemaOptions GetSchemaOptions =
                    new LinqToDB.SchemaProvider.GetSchemaOptions();

                LinqToDB.SchemaProvider.TableSchema ts = new LinqToDB.SchemaProvider.TableSchema();

                var sp = db.DataProvider.GetSchemaProvider();
                LinqToDB.SchemaProvider.DatabaseSchema dbs = sp.GetSchema(db, GetSchemaOptions);

                List <ColumnaSis> cols = dbs.Tables.Where(x => x.TableName == parametros[0].ToString()).SingleOrDefault().Columns.Select(x => new ColumnaSis()
                {
                    ColumnName = x.ColumnName, ColumnType = x.ColumnName, DataType = x.DataType, Description = x.Description, IsIdentity = x.IsIdentity, IsNullable = x.IsNullable, IsPrimaryKey = x.IsPrimaryKey, MemberName = x.MemberName, MemberType = x.MemberType, PrimaryKeyOrder = x.PrimaryKeyOrder, SystemType = x.SystemType, SkipOnInsert = x.SkipOnInsert, SkipOnUpdate = x.SkipOnUpdate, Table = x.Table
                }).ToList();

                if (cols.Count > 0)
                {
                    cols.Add(new ColumnaSis()
                    {
                        ColumnName = "modificado"
                    });
                }

                return(cols);
            }
        }
Esempio n. 2
0
        public void CargarTablas(ComboBox unCombo)
        {
            LinqToDB.SchemaProvider.GetSchemaOptions GetSchemaOptions =
                new LinqToDB.SchemaProvider.GetSchemaOptions();

            LinqToDB.SchemaProvider.TableSchema ts = new LinqToDB.SchemaProvider.TableSchema();
            using (ispDB dbcn = new ispDB())
            {
                var sp = dbcn.DataProvider.GetSchemaProvider();
                LinqToDB.SchemaProvider.DatabaseSchema db = sp.GetSchema(dbcn, GetSchemaOptions);
                unCombo.ValueMember   = "TableName";
                unCombo.DisplayMember = "TableName";
                unCombo.DataSource    = null;
                unCombo.DataSource    = db.Tables.OrderBy(x => x.TableName).ToList();
            }
        }
Esempio n. 3
0
        internal static void SetForeignKeyMemberName(GetSchemaOptions schemaOptions, TableSchema table, ForeignKeySchema key)
        {
            string?name = null;

            if (schemaOptions.GetAssociationMemberName != null)
            {
                name = schemaOptions.GetAssociationMemberName(key);

                if (name != null)
                {
                    key.MemberName = ToValidName(name);
                }
            }

            if (name == null)
            {
                name = key.MemberName;

                if (key.BackReference != null && key.ThisColumns.Count == 1 && key.ThisColumns[0].MemberName.ToLower().EndsWith("id"))
                {
                    name = key.ThisColumns[0].MemberName;
                    name = name.Substring(0, name.Length - "id".Length).TrimEnd('_');

                    if (table.ForeignKeys.Select(_ => _.MemberName).Concat(
                            table.Columns.Select(_ => _.MemberName)).Concat(
                            new[] { table.TypeName }).Any(_ => _ == name))
                    {
                        name = key.MemberName;
                    }
                }

                if (name == key.MemberName)
                {
                    if (name.StartsWith("FK_"))
                    {
                        name = name.Substring(3);
                    }

                    if (name.EndsWith("_BackReference"))
                    {
                        name = name.Substring(0, name.Length - "_BackReference".Length);
                    }

                    name = string.Join("", name
                                       .Split('_')
                                       .Where(_ =>
                                              _.Length > 0 && _ != table.TableName &&
                                              (table.SchemaName == null || table.IsDefaultSchema || _ != table.SchemaName))
                                       .ToArray());

                    var digitEnd = 0;
                    for (var i = name.Length - 1; i >= 0; i--)
                    {
                        if (char.IsDigit(name[i]))
                        {
                            digitEnd++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (digitEnd > 0)
                    {
                        name = name.Substring(0, name.Length - digitEnd);
                    }
                }

                if (string.IsNullOrEmpty(name))
                {
                    name = key.OtherTable != key.ThisTable ? key.OtherTable.TableName ! : key.KeyName;
                }

                if (table.ForeignKeys.Select(_ => _.MemberName).Concat(
                        table.Columns.Select(_ => _.MemberName)).Concat(
                        new[] { table.TypeName }).All(_ => _ != name))
                {
                    key.MemberName = ToValidName(name);
                }
            }
        }