简体   繁体   中英

C# | WPF | DataGrid - Binding to the sources from two Tables

I have a datagrid, named orderItemsGrid, which contains the columns (or TextColumn Headers, to prevent confusion) Item Name, Unit Price, Quantity, and Amount (Amount=Quantity*unitPrice) of each item that a customer has ordered in an order. I would like to fetch the info to this grid from a SQL Express 2008 R2 Database, called Business, using LINQ to SQL. But the problem is, the columns ItemName and Price exist in the table named ITEMS and the columns Quantity and Amount are in ORDER_ITEMS.

Relationships:
FK_ORDER_ITEMS_ORDERS (OrderID)
FK_ORDER_ITEMS_ITEMS (ItemID)

The database diagram is here:

Please revert with comments.

You can use joins in LINQ, that is not problem, in linq query you can create new type with columns what you just need, hat will be properties in that new type, you can give them other names . That list, result of query, can be DataSource for your grid. If you need help with joins or query tell

SOLUTION:

The new code has worked, but there is one problem - not a big one though - that it fetches all attributes of both objects. New Code: hxxp://i51.tinypic.com/13zs4ug.jpg Old Code: hxxp://i51.tinypic.com/29oppb8.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM