0

I got three tables to join named Books, Borrowers and Transactions. The database scheme is as below:

  1. Books(BookID,BookName,ISBN);
  2. Borrowers(BorrowerID,BorrowerName,BorrowerLevel);
  3. Transactions(TransactionID,BorrowerID,BookID,BorrowDate,ReturnDate);

The corresponding class are Book, Borrower and Transaction respectively. Now i would like to select BookID,BookName,BorrowerID,BorrowerName,BorrowDate and ReturnDate from these three tables and to show in a listview having gridview control. XAML Code :

<Grid>
        <ListView Margin="15,57,58,57" Name="borrowedBookList" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding }" KeyDown="borrowedBookList_KeyDown">
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn Width="80" Header="Borrower ID" DisplayMemberBinding="{Binding Path=BorrowerID}"/>
                        <GridViewColumn Width="220" Header="Borrower Name" DisplayMemberBinding="{Binding Path=BorrowerName}"/>
                        <GridViewColumn Width="220" Header="Book Name" DisplayMemberBinding="{Binding Path=BookName}"/>
                        <GridViewColumn Width="100" Header="Date" DisplayMemberBinding="{Binding Path=BorrowDate}"/>
                        <GridViewColumn Width="100" Header="Return Date" DisplayMemberBinding="{Binding Path=ReturnDate}"/>
                       </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>

Now how can i join these tables and assign the result datacontext into borrowedBookList?

Thankyou

Arefin Sami

arefinsami
  • 363
  • 2
  • 7
  • 18

2 Answers2

1
borrowedBookList.DataSource =
    from borrower in Borrowers
    join transaction in Transactions
        on borrower.BorrowerID equals transaction.BorrowerID
    join book in Books
        on transaction.BookID equals book.BookID
    select new
    {
        borrower.BorrowerID,
        borrower.BorrowerName,
        book.BookName,
        transaction.BorrowDate,
        transaction.ReturnDate,
    }

borrowedBookList.DataBind();
Thom Smith
  • 13,916
  • 6
  • 45
  • 91
0

have you looked into the hierarchicaldatatemplate class?

Your model or viewmodel would need to contain the respective relationships. From there, the appropriate datatemplate should work nicely.

Josh C.
  • 4,303
  • 5
  • 30
  • 51