Example #1
0
        private void FillRealTableSchema(ModifiedColumnsCollection cols)
        {
            var columns = cols.AllColumnsNames;
            var all     = _db.Query <ColumnSchema>(
                @"select COLUMN_NAME as ColumnName, DATA_TYPE as DataType
, cast (CHARACTER_MAXIMUM_LENGTH as varchar(5))as CharacterMaximumLength, cast (NUMERIC_PRECISION as varchar(5)) as NumericPrecision, cast (NUMERIC_SCALE as varchar(5)) as NumericScale, COLLATION_NAME as CollationName from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @0 and COLUMN_NAME in (@1)", cols.TableName, columns);

            foreach (var cs in all)
            {
                var column = cols[cs.ColumnName];
                column.Modifications.Current.Type      = ExtractType(cs);
                column.Modifications.Current.Collation = cs.CollationName;
            }

            var defaults = _db.Query <dynamic>(@"select c.name as colname, d.name as defname
from sys.tables t
    join
    sys.default_constraints d
        on d.parent_object_id = t.object_id
    join
    sys.columns c
        on c.object_id = t.object_id
        and c.column_id = d.parent_column_id
where t.name = @0
and c.name in (@1)", cols.TableName, columns);

            foreach (var def in defaults)
            {
                var column = cols[def.colname];
                column.Modifications.Current.DefaultConstraintName = def.defname;
            }
        }
Example #2
0
        /// <summary>
        /// Selects first row matching criteria and maps it to poco
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static IEnumerable <T> Query <T>(this IAccessDb db, Expression <Func <T, bool> > condition)
        {
            var builder = new ExpressionSqlBuilder <T>(db.Provider.BuilderHelper);

            builder
            .WriteSelect()
            .WriteSelectAllColumns()
            .WriteFrom()
            .Where(condition);
            return(db.Query <T>(builder.ToString(), builder.Parameters.ToArray()));
        }
Example #3
0
        private void FillRealTableSchema(TableSchema table)
        {
            var columns = table.ModifiedColumns.AllColumnsNames;
            // var tableName = SqlServerProvider.FormatName(table.Name);
            var all = Db.Query <ColumnSchema>(
                @"select COLUMN_NAME as ColumnName, DATA_TYPE as DataType
, cast (CHARACTER_MAXIMUM_LENGTH as varchar(5))as CharacterMaximumLength, cast (NUMERIC_PRECISION as varchar(5)) as NumericPrecision, cast (NUMERIC_SCALE as varchar(5)) as NumericScale, COLLATION_NAME as CollationName from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @0 and COLUMN_NAME in (@1)", table.Name, columns);

            foreach (var cs in all)
            {
                var column = table.ModifiedColumns[cs.ColumnName];
                column.Modifications.Current.Type      = ExtractType(cs);
                column.Modifications.Current.Collation = cs.CollationName;
            }
        }
Example #4
0
 public static List <T> Fetch <T>(this IAccessDb db, string sql, params object[] args)
 {
     return(db.Query <T>(sql, args).ToList());
 }