1.VIEW 页面显示代码
@foreach (var item in ViewBag.dyObject) { 用户名 地址 订单编号 城市代号 时间 订单状态 } @item.UserName @item.LocalAddress @item.BargainOrderCode @item.CityCode @item.UpdateTime @item.OrderStatus
2、Controller 控制器
public ActionResult UserOrder() { #region EF+linq 多表联查VIEW显示列表
var userOrdeList = (from user in _DbContext.UserInfo_tests
join order in _DbContext.TRA_BargainOrders on user.Id equals order.UserIDselect new
{uname = user.UserName,
uaddress = user.LocalAddress, bargainOrderCode = order.BargainOrderCode, cityCode = order.CityCode, updateTime = order.UpdateTime, orderStatus = order.OrderStatus } ).ToList(); List<dynamic> userList = new List<dynamic>(); foreach (var data in userOrdeList.ToList()) { dynamic dyObject = new ExpandoObject(); dyObject.UserName = data.uname; dyObject.LocalAddress = data.uaddress; dyObject.BargainOrderCode = data.bargainOrderCode; dyObject.CityCode = data.cityCode; dyObject.UpdateTime = data.updateTime; dyObject.OrderStatus = data.orderStatus; userList.Add(dyObject); } ViewBag.dyObject = userList;return View();
#endregion }
3、实体model 和数据库操作在此省略