C# 将两个数据库表绑定到同一个Datagrid
我想知道如何在同一个wpf数据网格中使用来自更多Sql Compact数据库的两个不同表。我目前有两个表,Accounts和AccountType。Accounts中有一个外键将其链接到AccountType,在AccountType中它是该类型的ID号。我在Accounts中还有一个字段将其链接到父帐户(本质上是另一个帐户id的外键)。下面是我必须将datagrid绑定到Accounts表的wpfC# 将两个数据库表绑定到同一个Datagrid,c#,wpf,binding,datagrid,C#,Wpf,Binding,Datagrid,我想知道如何在同一个wpf数据网格中使用来自更多Sql Compact数据库的两个不同表。我目前有两个表,Accounts和AccountType。Accounts中有一个外键将其链接到AccountType,在AccountType中它是该类型的ID号。我在Accounts中还有一个字段将其链接到父帐户(本质上是另一个帐户id的外键)。下面是我必须将datagrid绑定到Accounts表的wpf <Window.Resources> <my:MyAccountant
<Window.Resources>
<my:MyAccountantDBDataSet x:Key="myAccountantDBDataSet" />
<CollectionViewSource x:Key="accountsViewSource" Source="{Binding Path=Accounts, Source={StaticResource myAccountantDBDataSet}}" />
<CollectionViewSource x:Key="accountTypeViewSource" Source="{Binding Path=AccountType, Source={StaticResource myAccountantDBDataSet}}" />
</Window.Resources>
<DataGrid Background="DimGray" Name="GridAccounts" CanUserAddRows="True" CanUserDeleteRows="True" ItemsSource="{Binding Source={StaticResource accountsViewSource}}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=AccountName}"/>
<DataGridTextColumn Header="Description" Binding="{Binding Path=AccountDesc}" />
<DataGridTextColumn Header="Number" Binding="{Binding Path=AccountNumber}"/>
<DataGridTextColumn Header="Type" />
<DataGridTextColumn Header="Parent Account" />
</DataGrid.Columns>
</DataGrid>
我想做的是将Type列绑定到AccountType表,并显示类型名称,而不是类型id。同样,对于父帐户,我不想显示id号,但如果它有父帐户,则显示帐户名称。如何对这两列执行此操作?能否创建一个连接数据库中两个表的视图,然后从C#查询该视图?
通过这种方式,所有处理都在数据库上完成,并且可能比从应用程序中更高效。等等,这可以通过
JOIN
ING表轻松实现。你可以读到关于汉克斯·凯文的书。我知道所有关于加入的事情,我只是想知道是否有一种不同的绑定方式。