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; }
    }

     
  • 相关阅读:
    Python爬虫一
    Python爬虫二
    DRF框架中的演变View
    计算时间复杂度例题
    vue2.x webpack打包资源路径问题
    vs code运行c语言 控制台乱码 问题
    解决视频的声音和画面不同步问题
    c语言数据结构,静态链表,结构体数组
    swagger @ApiModel添加实体类不生效
    计算及校验海明码的3个举例
  • 原文地址:https://www.cnblogs.com/CoreColor/p/13448855.html
Copyright © 2011-2022 走看看