public ICollection <DatabaseFile> GetDatabaseFiles()
        {
            string      sql     = "SELECT name, physical_name, state_desc, (size * 8.0)*1000 AS size, CASE WHEN max_size = -1 THEN 9999999 ELSE (max_size * 8.0)*1000 END AS max_size FROM sys.database_files;";
            SqlCommand  command = new SqlCommand(sql);
            IDataReader reader  = SqlServerCommandHelper.ExecuteSqlQuery(command);

            var items = new List <DatabaseFile>();

            while (reader.Read())
            {
                items
                .Add
                (
                    new DatabaseFile
                    (
                        name:
                        reader.GetColumnValue("name").ToString(),
                        physicalFileName:
                        reader.GetColumnValue("physical_name").ToString(),
                        sizeInBytes:
                        Convert.ToInt64(reader.GetColumnValue("size")),
                        stateDesc:
                        reader.GetColumnValue("state_desc").ToString()
                    )
                );
            }

            return(items);
        }
示例#2
0
        public bool Exists(int id)
        {
            string     sql     = "select 1 from " + GetTableName() + WhereIdEquals();
            SqlCommand command = new SqlCommand(sql);

            AddIdParameterToCommand(command, id);
            IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command);

            return(reader.Read());
        }
示例#3
0
        public bool InUse(string userId)
        {
            string     sql     = "select 1 from vw_user_ids_in_use where userid = @userid";
            SqlCommand command = new SqlCommand(sql);

            command.Parameters.AddWithValue("@userid", userId);
            IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command);

            return(reader.Read());
        }
示例#4
0
        public T Get(int id)
        {
            string     sql     = GetSelectStatement() + WhereIdEquals();
            SqlCommand command = new SqlCommand(sql);

            AddIdParameterToCommand(command, id);
            IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command);

            reader.Read();
            return(GetItemFromDataReader(reader));
        }
示例#5
0
        public ICollection <T> GetAll()
        {
            string      sql     = GetSelectStatement() + ";";
            SqlCommand  command = new SqlCommand(sql);
            IDataReader reader  = SqlServerCommandHelper.ExecuteSqlQuery(command);

            var items = new List <T>();

            while (reader.Read())
            {
                T item = GetItemFromDataReader(reader);
                items.Add(item);
            }

            return(items);
        }
示例#6
0
        public ICollection <T> GetMatchingOn(int foreignKeyId)
        {
            string     sql     = GetSelectStatement() + WhereForeignKeyEquals() + ";";
            SqlCommand command = new SqlCommand(sql);

            AddIdParameterToCommand(command, foreignKeyId);
            IDataReader reader = SqlServerCommandHelper.ExecuteSqlQuery(command);

            var items = new List <T>();

            while (reader.Read())
            {
                T item = GetItemFromDataReader(reader);
                items.Add(item);
            }

            return(items);
        }