帮助使用数据库数据XAML修改datagrid

时间:2011-05-01 22:34:55

标签: c# silverlight wcf xaml datagrid

我有以下XAML代码:

    <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}" Header="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>

代码有一些像seatId和showId这样的标题,我希望他们能够显示座位和节目的实际名称,但我如何查询,我在Silverlight应用程序中使用域服务和上下文。 / p>

如果您需要更多信息,请告诉我。

感谢。

编辑: 用于绑定的查询:

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;

编辑: 数据模型:

enter image description here

编辑: 从域服务查询代码:

    public IQueryable<Ticket> GetTickets()
    {
        return this.ObjectContext.Tickets.Include("Seat");
    }

1 个答案:

答案 0 :(得分:1)

给你一个完整的答案......

这是SO上的link,用于描述导航属性

如果您有具有SeatID的票证实体(以数据库术语,外键),您可以创建一个导航属性,将票证实体连接到席位实体。在SQL术语中,这类似于编写类似的内容:

Select Ticket.Name, Seats.SeatName JOIN Seats ON Ticket.SeatID = Seats.SeatID

在你的情况下,你会使用类似的东西:

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;

编辑:在Tickets对象的元数据中,您应该看到类似

的内容
public Seat Seats { get; set; }

添加:

[Include]
public Seat Seats { get; set; }