sskcal 2016-04-16 00:54 采纳率: 40%
浏览 1479
已采纳

MVC5 entity framework6 表链接查询 怎么回事?

model代码如下:

 public class Orders
    {
        [Key]
        public int OrdersId { set; get; }
        //订单号
        public string OrdersNum { set; get; }

        public string ProductName { set; get; }

        public int ProductId { set; get; }

        public string PriceName { set; get; }

        public int PriceId { set; get; }

        //订购时间
        public DateTime PlaceOrdersTime { set; get; }

        //付款时间
        public DateTime PaymentTime { set; get; }

        //零售价
        public decimal ProposalPrice { set; get; }

        //结算价
        public decimal SettlementPrice { set; get; }

        //成本价
        public decimal CostPrice { set; get; }

        //订购数量
        public int OrderQuantity { set; get; }

        //总价
        public decimal TotalPrice { set; get; }

        //支付方式
        public string PayMode { set; get; }

        //支付总金额
        public decimal PayTotalPrice { set; get; }

        //订单状态
        public string OrdersState { set; get; }
        //哪个用户下的订单
        public string UserId { set; get; }

        public virtual ICollection<OrdersInfo> OrdersInfo { get; set; }

    }


    public class OrdersInfo 
    {
        [Key]
        public int OrdersInfoId { set; get; }

        public int OrdersId { set; get; }

        //联系人
        public string Contacts { set; get; }
        public string PhoneNumber { set; get; }

        public string IdCardNumber { set; get; }

        //使用日期
        public DateTime UseDate { set; get; }

        //验证码
        public string Code { set; get; }

        //验证码数量
        public int CodeQuantity { set; get; }


        //验证码未使用数量
        public int CodeNotUsedQuantity { set; get; }

        //验证码使用数量
        public int CodeUseQuantity { set; get; }
        //验证码有效期
        public DateTime CodeShelfLife { set; get; }

        //验证码核销时间
        public DateTime CodeUsedTime { set; get; }

        public string Remark { set; get; }
        public virtual Orders Orders { get; set; }

    }

控制器代码如下:

         public ActionResult RestaurantOrdersList(string OrdersNum, string ProductName, string Contacts, string PhoneNumber, int page = 1)
        {
            ViewBag.OrdersNum = OrdersNum;
            ViewBag.ProductName = ProductName;
            ViewBag.Contacts = Contacts;
            ViewBag.PhoneNumber = PhoneNumber;

            int pageSize = 10;
            var OrdersDb = from a in db.Orders
                           join b in db.OrdersInfo
                           on new { a.OrdersId } equals new { b.OrdersId }
                           select new { a, b };


            var userId = User.Identity.GetUserId();

                OrdersDb.Where(s => s.a.UserId == userId);

                if (!string.IsNullOrEmpty(OrdersNum))
                {
                    OrdersDb = OrdersDb.Where(s => s.a.OrdersNum.IndexOf(OrdersNum) > -1);
                }
                if (!string.IsNullOrEmpty(ProductName))
                {
                    OrdersDb = OrdersDb.Where(s => s.a.ProductName.Contains(ProductName));
                }

                if (!string.IsNullOrEmpty(Contacts))
                {
                    OrdersDb = OrdersDb.Where(s => s.b.Contacts.Contains(Contacts));
                }
                if (!string.IsNullOrEmpty(PhoneNumber))
                {
                    OrdersDb = OrdersDb.Where(s => s.b.PhoneNumber == PhoneNumber);
                }

                ViewBag.RestaurantOrdersList = OrdersDb.OrderByDescending(x => x.a.PlaceOrdersTime).ToPagedList(page, pageSize);

            return View();
        }

View代码如下:

 @foreach (var l in list)
            {

                @l.a.ProductName
                        }

错误如下:

图片说明

  • 写回答

4条回答 默认 最新

  • sskcal 2016-04-16 01:13
    关注

    图片说明

    caozhy 兄弟,还是不行。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格