zoukankan      html  css  js  c++  java
  • 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; }
    }

     
  • 相关阅读:
    洛谷 P2486 [SDOI2011]染色 树链剖分
    js 随机打乱数组
    js 中concat()和slice()方法介绍
    encodeURIComponent() 函数的使用
    mysql中LOCATE和CASE WHEN...THEN...ELSE...END结合用法
    Java多态的理解
    JQuery UI完成自动匹配的的下拉列表步骤
    marquee 标签的使用介绍
    orcale数据恢复
    sql中replace的用法
  • 原文地址:https://www.cnblogs.com/CoreColor/p/13448855.html
Copyright © 2011-2022 走看看