1

我想从查询中使用此命令过滤掉结果,但出现此错误:

执行问题

这是导致错误的代码:

    private void Bookings_Loaded(object sender, RoutedEventArgs e)
    {
        WpfApplication7.AllensCroftEntities1 allensCroftEntities1 = new WpfApplication7.AllensCroftEntities1();

        // Load data into Bookings. You can modify this code as needed.
        var bookingsViewSource = ((CollectionViewSource)(this.FindResource("bookingsViewSource")));
        var bookingsQuery = this.GetBookingsQuery(allensCroftEntities1).Where(x => x.Date == variables.date);
        bookingsViewSource.Source = bookingsQuery.Execute(MergeOption.AppendOnly);

   private System.Data.Objects.ObjectQuery<Booking> GetBookingsQuery(AllensCroftEntities1 allensCroftEntities1)
    {

      EDIT

这里是

        System.Data.Objects.ObjectQuery<WpfApplication7.Booking> bookingsQuery = allensCroftEntities1.Bookings;
        // To explicitly load data, you may need to add Include methods like below:
        // bookingsQuery = bookingsQuery.Include("Bookings.Client").
        // For more information, please see http://go.microsoft.com/fwlink/?LinkId=157380
        // Update the query to include Room.Bookings data in Bookings. You can modify this code as needed.
        bookingsQuery = bookingsQuery.Include("Room.Bookings");
        // Returns an ObjectQuery.
        return bookingsQuery;
    }

顺便编辑这里是我的问题的视频,如果它有助于解决问题 的视频

现在编辑我收到此错误: 列表错误

4

2 回答 2

1

如果要更改查询中的合并选项,则应使用

((ObjectQuery)bookingsQuery).MergeOption = MergeOption.AppendOnly;

如果您希望执行查询,您可以调用.ToList()这将执行查询并应用您的过滤器

你的代码应该像

var bookingsQuery = this.GetBookingsQuery(allensCroftEntities1).Where(x => x.Date == variables.date);
((ObjectQuery)bookingsQuery).MergeOption = MergeOption.AppendOnly;
bookingsViewSource.Source = bookingsQuery.ToList();
于 2013-03-17T12:16:06.247 回答
0

没有执行。bookingsQuery 将作为数据消费者迭代查询定义的数据的一部分自动“执行”。

于 2013-03-17T12:07:05.410 回答