zoukankan      html  css  js  c++  java
  • PetaPoco使用

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <connectionStrings>
        <add name="connectionStringName" connectionString="server=localhost;database=0914;uid=sa;password=850414;" />
      </connectionStrings>
    </configuration>
    复制代码
    复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        public class Achievement
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string Course { get; set; }
            public int Degree { get; set; }
        }
    }
    复制代码
    复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var db = new PetaPoco.Database("connectionStringName");
    
                // Show all articles    
                foreach (var a in db.Query<Achievement>("SELECT * FROM Achievement"))
                {
                    Console.WriteLine("{0} - {1}", a.Id, a.Name);
                }
    
                //分页
                Console.WriteLine("分页");
                PetaPoco.Page<Achievement> result = db.Page<Achievement>(1, 3, // <-- page number and items per page
            "SELECT * FROM Achievement WHERE Course=@0 ORDER BY Degree DESC", "C#程序设计");
                result.Items.ForEach(delegate(Achievement entity) {
                    Console.WriteLine("PageItem:{0}-{1}-{2}-{3}",entity.Id,entity.Name,entity.Course,entity.Degree);
                });
    
                Console.Read();
            }
        }
    }


    复制代码
    注意:
      这里的分页执行的语句是:

    SELECT * FROM 
    (SELECT ROW_NUMBER() OVER (ORDER BY Degree DESC) peta_rn, * FROM Achievement WHERE Course=N'C#程序设计') peta_paged 
    WHERE peta_rn>0 AND peta_rn<=3

  • 相关阅读:
    PHP实现http与https转化
    HTTP和HTTPS详解
    如何防止SWF文件被反编译
    Swf Decrypt详解
    PCIE体系结构
    windows设备驱动安装指南
    [转]RegOpenKeyEx函数失败的问题
    用Setup系列函数完成驱动卸载安装[驱动安装卸载程序]
    Skipped Rebuild All: Project with VS2008
    LINK : fatal error LNK1000: Internal error during IncrBuildImage
  • 原文地址:https://www.cnblogs.com/shiningrise/p/6693177.html
Copyright © 2011-2022 走看看