• EF


    ShopDB db = new ShopDB();

    //分页显示商品
    [HttpGet]
    public PageDate GetGoods(int index, int size)
    {
    PageDate page = new PageDate();
    var list = db.Goods.ToList();
    var count = list.Count();
    page.List = list.OrderBy(x => x.GId).Skip((index - 1) * size).Take(size).ToList();
    page.PageCount = count / size + (count % size == 0 ? 0 : 1);
    return page;
    }
    //分页存储过程显示
    [HttpGet]
    public PageDate GetGoods2(int index, int size)
    {
    //实例化参数
    SqlParameter[] parameters = new SqlParameter[]
    {
    new SqlParameter("@index",index),
    new SqlParameter("@size",size),
    new SqlParameter("@totalcount",SqlDbType.Int), //总数据数
    new SqlParameter("@pagecount",SqlDbType.Int), //总页数
    };
    //指定输出参数
    parameters[2].Direction = ParameterDirection.Output;
    parameters[3].Direction = ParameterDirection.Output;

    //存储过程查询
    var list = db.Database.SqlQuery<Goods>("exec sp_Show @index,@size,@totalcount out,@pagecount out", parameters).ToList();

    PageDate page = new PageDate();
    page.List = list;
    page.PageCount = int.Parse(parameters[3].Value.ToString());
    return page;
    }

    //商品表
    public class Goods
    {
    [Key]
    public int GId { get; set; }
    public string Name { get; set; }
    public string Img { get; set; }
    public decimal Price { get; set; }
    }
    //购物车表
    public class ShopCar
    {
    [Key]
    public int SId { get; set; }
    public int BuyCount { get; set; }

    public Goods Goods { get; set; }
    public int GoodsGId { get; set; }
    }
    //订单表
    public class Order
    {
    [Key]
    public int OId { get; set; }
    public string OrderNum { get; set; }
    public DateTime CreateTime { get; set; }

    public Goods Goods { get; set; }
    public int GoodsGId { get; set; }
    }

    public class PageDate
    {
    public List<Goods> List { get; set; }
    public int PageCount { get; set; }
    }

     
  • 相关阅读:
    各种工具的使用 tricks
    各种工具的使用 tricks
    全栈工程师之路(二)—— JavaScript(网页前端脚本语言)
    全栈工程师之路(二)—— JavaScript(网页前端脚本语言)
    CSS(网页样式语言)基础
    CSS(网页样式语言)基础
    辨异 —— 机器学习概念辨异、模型理解
    辨异 —— 机器学习概念辨异、模型理解
    程序猿/媛段子
    tabhost中activity跳转动画不显示的解决办法
  • 原文地址:https://www.cnblogs.com/CoreColor/p/13448855.html
Copyright © 2020-2023  润新知