EF 使用存储过程 sql语句

DAL层调用Sql语句

var result = DbContext.Database.SqlQuery<FeedBackSummary>("Sql语句").ToList();  


DAL层调用存储过程
public List<FeedBackSummary> GetSummaryList(string datefrom, string dateto, string code)
        {
            
              SqlParameter[] paramet = { new SqlParameter("@TourCode", code), 
                                   new SqlParameter("@DateTimeStart", datefrom),
                                   new SqlParameter("@DateTimeEnd", dateto) };
              var result = DbContext.Database.SqlQuery<FeedBackSummary>("exec FeedBack_Summary @TourCode,@DateTimeStart,@DateTimeEnd", paramet).ToList();
              return result;
         }

FeedBackSummary类是存储过程返回表对应建立的 proc_model


控制器层   返回的数据如果还要处理一层  示例图片 存储过程数据和页面显示数据
 public ActionResult GetFeedBackSummary()
        {
            string datefrom = Request["datefrom"]!=null?Request["datefrom"]:"";
            string dateto = Request["dateto"] != null ? Request["dateto"] : "";
            string code = Request["code"] != null ? Request["code"] : "";
            //得到列表数据
            List<FeedBackSummary> model = new PA_Dal.ContactUs.ContactUsDal().GetSummaryList(datefrom, dateto, code);
            //还需要一层来处理数据变成一对多的viewmodel
            List<FeedBackSummaryviewmodel> viewmodel = new List<FeedBackSummaryviewmodel>();
            //按照想要的一 为KEY 对应的多为 list
            var groups = model.GroupBy(m => new { m.TourCode, m.Categories }).ToList();
            foreach (var item in groups)
            {
                FeedBackSummaryviewmodel vm=new FeedBackSummaryviewmodel();
                vm.key = item.Key.TourCode+"   "+item.Key.Categories;
                vm.list = item.ToList();
                viewmodel.Add(vm);
            }
            return View(viewmodel);
        }


model

存储过程接收model
 public class FeedBackSummary
    {
       
         [Key]
      
         public int PeopleCount { get; set; }
          public string TourCode { get;set;}
          public string Categories { get; set; }
          public string CityOrType { get; set; }
          public int EXCELLENT { get; set; }
          public int GOOD { get; set; }
          public int SATISFACTORY { get; set; }
          public int BELOWEXPECTATION { get; set; }
          public int POOR { get; set; }
         
    }
页面数据接收model
    public class FeedBackSummaryviewmodel
    {
        [Key]
        public string key { get; set; }
        public List<FeedBackSummary> list { get; set; }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值