左连接查询 LinqToSql 的问题

发布于 2024-11-18 15:46:34 字数 1458 浏览 3 评论 0原文

      IBookingRepository bookingResp = new BookingRepository();
        IQueryable<bookingTest> bookings = bookingResp.GetAllBookingsByView();
       var grid = new System.Web.UI.WebControls.GridView();
        grid.DataSource = from booking in bookings
                        join f in getallAttendees on booking.UserID equals f.UserID into fg
                        from fgi in fg.DefaultIfEmpty() //Where(f => f.EventID == booking.EventID)
                        where
                              booking.EventID == id


                          select new
                          {
                              EventID = booking.EventID,

                              UserID = booking.UserID,
                              TrackName = booking.Name,
                              BookingStatus = booking.StatusID,
                               AttendeeName = booking.FirstName,
                             // name = account.FirstName,
                              AmountPaid = booking.Cost,
                              AttendeeAddress = booking.DeliveryAdd1,
                              City = booking.DeliveryCity,
                               Postcode = booking.Postcode,
                              Date = booking.DateAdded,
                              hel = fgi == null ? null : fgi.HelmetsPurchased }// Product table 

您好,上面的查询不会执行,而是会出现错误:指定的 LINQ 表达式包含对与不同上下文关联的查询的引用。任何人都可以发现查询的问题所在。

      IBookingRepository bookingResp = new BookingRepository();
        IQueryable<bookingTest> bookings = bookingResp.GetAllBookingsByView();
       var grid = new System.Web.UI.WebControls.GridView();
        grid.DataSource = from booking in bookings
                        join f in getallAttendees on booking.UserID equals f.UserID into fg
                        from fgi in fg.DefaultIfEmpty() //Where(f => f.EventID == booking.EventID)
                        where
                              booking.EventID == id


                          select new
                          {
                              EventID = booking.EventID,

                              UserID = booking.UserID,
                              TrackName = booking.Name,
                              BookingStatus = booking.StatusID,
                               AttendeeName = booking.FirstName,
                             // name = account.FirstName,
                              AmountPaid = booking.Cost,
                              AttendeeAddress = booking.DeliveryAdd1,
                              City = booking.DeliveryCity,
                               Postcode = booking.Postcode,
                              Date = booking.DateAdded,
                              hel = fgi == null ? null : fgi.HelmetsPurchased }// Product table 

Hi, the above query doesnt executes it gives an error: The specified LINQ expression contains references to queries that are associated with different contexts. Any one can spot the what the problem is with the query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2024-11-25 15:46:34

我认为您的 getAllAttendeesbookings 来自不同的上下文,因此您将无法加入它们。要给出更准确的答案,您需要显示 bookingsgetAllAttendees 的来源。

I think that your getAllAttendees is from a different context than bookings so you won't be able to join them. To give a more exact answer you need to show where bookings and getAllAttendees comes from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文