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