Xceed DataGrid QueryableSource和DbContext

时间:2013-04-24 13:40:29

标签: dbcontext xceed

我正在尝试实现DataGridVirtualizingQueryableCollectionViewSource,例如文档:http://doc.xceedsoft.com/products/xceedwpfdatagrid/Xceed.Wpf.DataGrid.v4.5~Xceed.Wpf.DataGrid.DataGridVirtualizingQueryableCollectionViewSource.html
使用ObjectContext API一切正常。
但是,使用DbContext API时,不显示单元格内容。
有没有人知道这个?

/// <summary>
/// WITH THIS WORKS.
/// </summary>
public partial class AdventureWorksEntities : ObjectContext 

/// <summary>
/// WITH THIS DOES NOT WORK.
/// </summary> 
public partial class AdventureWorksEntities : DbContext 

我的来源如下:

<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
    <Grid.Resources>

        <xcdg:DataGridVirtualizingQueryableCollectionViewSource 
            x:Key="cvs_queryableSource"
            QueryableSource="{Binding Path=QueryableSource}"/>

    </Grid.Resources>
    <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvs_queryableSource}}">
    </xcdg:DataGridControl>
</Grid>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.DataContext = this;
        InitializeComponent();
    }

    public IQueryable QueryableSource
    {
        get
        {
            if (m_queryable == null)
            {
                m_northwind = new AdventureWorksEntities();
                m_queryable = m_northwind.Contact;
            }
            return m_queryable;
        }
    }

    private AdventureWorksEntities m_northwind;
    private IQueryable m_queryable;
}

谢谢!

1 个答案:

答案 0 :(得分:1)

我不知道为什么,但我的查询中的一个简单的OrderBy解决了这个问题。

public IQueryable QueryableSource
{
    get
    {
        if (m_queryable == null)
        {
            m_northwind = new AdventureWorksEntities();
            m_queryable = m_northwind.Contact.OrderBy(p => p.SomeField);
        }
        return m_queryable;
    }
}

再次感谢!