コード例 #1
0
        public List <T> SupplyPageOfData(int pageIndex, int pageSize)
        {
            List <T> result = new List <T>();

            // Retrieve the specified number of rows from the database, starting
            // with the row specified by the lowerPageBoundary parameter.
            SelectPageOfDataCmd.Parameters.Add(Database.CreateParameter("@pageSize", pageSize, SelectPageOfDataCmd));
            SelectPageOfDataCmd.Parameters.Add(Database.CreateParameter("@offset", pageIndex * pageSize, SelectPageOfDataCmd));
            using (DbDataReader reader = SelectPageOfDataCmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    result.Add(ConstructFromRecord(reader));
                }
            }
            return(result);
        }
コード例 #2
0
        public LemmaRepository(LemmaDatabase db, string tableName, string[] columnNames)
        {
            Database   = db;
            TableName  = tableName;
            ColumNames = columnNames;

            InsertCmd = db.CreateCommand("insert into " + TableName + "(word," + string.Join(",", columnNames)
                                         + ") values(@word, @" + string.Join(", @", columnNames) + ")");
            InsertCmd.Prepare();
            string[] columnSetters = columnNames.Select(x => x + "=@" + x).ToArray(); // x=@x
            UpdateCmd = db.CreateCommand("update " + TableName + " set word=@word, " + string.Join(", ", columnSetters) + " where id=@id");
            UpdateCmd.Prepare();
            DeleteCmd = db.CreateCommand("delete from " + TableName + " where id=@id");
            DeleteCmd.Prepare();
            CountCmd = db.CreateCommand("select count(*) from " + TableName);
            CountCmd.Prepare();
            SelectByIdCmd = db.CreateCommand("select * from " + TableName + " where id=@id");
            SelectByIdCmd.Prepare();
            SelectPageOfDataCmd = db.CreateCommand("select * from " + TableName + " limit @pageSize offset @offset");
            SelectPageOfDataCmd.Prepare();
        }