Help modify datagrid with database data XAML
I have the following XAML code:
<sdk:DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding ElementName=ticketDomainDataSource, Path=Data}" Margin="8,43,0,0" Name="ticketDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="795">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="ticketNameColumn" Binding="{Binding Path=ticketName}" Header="Ticket Name" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketDescColumn" Binding="{Binding Path=ticketDesc}" Head开发者_运维技巧er="Ticket Desc" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketNumberColumn" Binding="{Binding Path=ticketNumber}" Header="Ticket Number" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketTypeIdColumn" Binding="{Binding Path=ticketTypeId}" Header="Ticket Type Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="seatIdColumn" Binding="{Binding Path=seatId}" Header="Seat Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="showIdColumn" Binding="{Binding Path=showId}" Header="Show Id" Width="SizeToHeader" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
The code has certain headers like, seatId and showId, I would like for them to show the actual name of the seat and show, but how would I query this, I am using domain services and contexts in my Silverlight application.
If you need more info please let me know.
Thanks.
EDIT: Query used for binding:
EntityQuery<Web.Ticket> query =
from t in _ticketContext.GetTicketsQuery()
where t.bookingId == data.bookingId
select t;
LoadOperation<Web.Ticket> loadOp = _ticketContext.Load(query);
tk.ticketDataGrid.ItemsSource = loadOp.Entities;
EDIT: Data Model:
EDIT: Query code from domain service:
public IQueryable<Ticket> GetTickets()
{
return this.ObjectContext.Tickets.Include("Seat");
}
To give you a full answer...
Here's a link on SO that describes Navigation Properties
If you have a Tickets Entity with a SeatID (in DB terms, a foreign key), you can create a Navigation property that will connect the Tickets Entity to a Seats Entity. In SQL terms, this would be akin to writing something like:
Select Ticket.Name, Seats.SeatName JOIN Seats ON Ticket.SeatID = Seats.SeatID
In your case, you'd use something like:
EntityQuery<Web.Ticket> query =
from t in _ticketContext.GetTicketsQuery().Include("Seats")
where t.bookingId == data.bookingId
select t;
LoadOperation<Web.Ticket> loadOp = _ticketContext.Load(query);
tk.ticketDataGrid.ItemsSource = loadOp.Entities;
Edit: In your metadata for your Tickets object, you should see something like
public Seat Seats { get; set; }
Add this:
[Include]
public Seat Seats { get; set; }
精彩评论