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

     
  • 相关阅读:
    读写文件
    c++ 中的 -> :: : .
    CDH安装步骤
    MySQL安全配置向导mysql_secure_installation详解
    Linux下彻底卸载mysql详解
    安装mysql警告: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    为Hadoop集群选择合适的硬件配置
    利用cm压缩包手动安装cm和cdh
    CM5.11与CDH5.11安装使用说明
    法的本体
  • 原文地址:https://www.cnblogs.com/CoreColor/p/13448855.html
Copyright © 2011-2022 走看看