2

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

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:

enter image description here

EDIT: Query code from domain service:

    public IQueryable<Ticket> GetTickets()
    {
        return this.ObjectContext.Tickets.Include("Seat");
    }
Sandeep Bansal
  • 6,280
  • 17
  • 84
  • 126
  • Need more info. Not reaching the problem. Is there any data binding working? – Guilherme Duarte May 01 '11 at 22:45
  • All the data binding is working, the thing is all the binding is done on the ticketDomainDataSource, I would like to use a different data source (different table in the database) to receive the values of the seatId, how would I manage this? – Sandeep Bansal May 01 '11 at 22:50
  • Are you using EF? ADO.NET Data Model? With a DomainContext, if you have a navigation property set up, you can just drop a .Include("YourSeatTableHere") to eager load the data into your object, which would allow you to set Path=SeatName. – Scott Silvi May 01 '11 at 23:29
  • Yes I am using a ADO.NET Datamodel with a datacontext, I don't really know how to set a .Include? can you fill me in, thanks – Sandeep Bansal May 01 '11 at 23:36
  • You say the databinding is working correctly so far, which means you are already retrieving data. Why don't you show that code, instead of the XAML which doesn't actually have a problem? – slugster May 01 '11 at 23:54
  • The reason the data is showing is because it is connected to the ticketDomainDataSource, which lists a list of the tickets from the ticket table, so it's just displaying a list of them. But I would like to change the id of seatID to the easier to read representation – Sandeep Bansal May 01 '11 at 23:56
  • When you're calling your getter, you can say something like from t in _customerContext.Tickets.Include("YourSeatTableHere") select t... as long as you have a navigation property that goes from your Tickets Table to your Seats table, it will automatically pull in all of the Seat information, which will put the associated seat records (for a given tickeT) into the domaincontext – Scott Silvi May 01 '11 at 23:56
  • OK I get you, there isn't an include where you state in your comment. I have edited my answer with my query code. – Sandeep Bansal May 02 '11 at 00:02

1 Answers1

1

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; }
Community
  • 1
  • 1
Scott Silvi
  • 3,059
  • 5
  • 40
  • 63
  • Thanks for editing your answer to match my code, but the Include() is not available to be used, I only get the property IncludeTotalCount – Sandeep Bansal May 02 '11 at 00:07
  • Do you have a navigation property set up in your edm? If you right-click on the entity you can Add > Navigation property. Also - I moved the include in my latest edit. My fault. – Scott Silvi May 02 '11 at 00:13
  • Navigation properties have been included, as you can see in my question, I have included the design model section. Also the Include in the part you have changed it to doesn't work either. still just shows IncludeTotalCount. – Sandeep Bansal May 02 '11 at 00:19
  • Ah... in your actual GetTicketsQuery, on the domainservice side, you can use the .Include("Seat"). – Scott Silvi May 02 '11 at 00:23
  • ooo, OK so I've done that now, I will show the code in my answer. But when changing the path to seatRow, it doesn't show anything. +1 for what you've done so far. – Sandeep Bansal May 02 '11 at 00:29
  • Keep in mind that it's not just pulling in all of your seat properties into the parent object... its pulling in a reference to your Seats object... so the full binding would be something like Tickets.Seats.SeatName. Set a breakpoint on your query and after it executes, take a look through your object. – Scott Silvi May 02 '11 at 00:39
  • I gave: a try and it didn't work, is there something I'm doing wrong? I had also tried Tickets.Seats.seatName – Sandeep Bansal May 02 '11 at 00:43
  • Its probably going to be Seat.seatRow. Like I said in the above, take a look through your query results & see the object being returned. The reference to 'Ticket.Seat.seatRow' was merely to point out the OO structure of the resultant set of data. – Scott Silvi May 02 '11 at 00:45
  • I've tried Seat.seatRow, Tickets.Seat.seatRow and Ticket.Seat.seatRow, yet nothing comes out. How would I be able to see what result the query comes out with? – Sandeep Bansal May 02 '11 at 00:52
  • Are you familiar with setting breakpoints in code? [Here's an example](http://www.blackwasp.co.uk/VSBreakpoints.aspx) of doing so. You can simply tell the code to pause when it hits a breakpoint, and you can step through your code line by line. It allows you to see the value of variables at moments in time within your code. In your example, after executing the query, you can drill down into your query object to see the results. A question about using breakpoints is probably larger than I can fit in a comment though :) – Scott Silvi May 02 '11 at 00:59
  • For example, after executing the query (if you set a breakpoint on the line 'LoadOperation LoadOp....", the query will already have run)... if you use the immediate window, you can type ? query.First().Seats.First().SeatName and you should see the seat name. Or using the Locals Window, you can drill down into the object by clicking on the [+] next to query, then click on the [+] next to Results View, then click on the [+] next to the first result, you can keep drilling into the Seats property. – Scott Silvi May 02 '11 at 01:01
  • Strange..the results view gave a Empty "Enumeration yielded no Results" string – Sandeep Bansal May 02 '11 at 01:15
  • I even put a pause on the next line incase the query didn't execute, still yeilding no results. – Sandeep Bansal May 02 '11 at 01:18
  • are your bindings showing data? do you know how to run a sql trace to see what the sql code that hits the database was? – Scott Silvi May 02 '11 at 06:37
  • No I don't, I'm surprised that it's actually something very trivial to get data from another table – Sandeep Bansal May 02 '11 at 11:36
  • Once you figure out the twists & turns of working with a domaincontext, its very powerful and quick to code. What about the 'are your bindings showing data' question.. – Scott Silvi May 02 '11 at 16:30
  • 1
    The bindings are showing the data, the seatId is showing as the Id it corresponds to in the database, I had also tried to copy the code from the Seat generated class in the domain service and enter it into the tickets, that did show the Seat and it's properties but when using Seat.seatRow did not show any debugged the code as well. – Sandeep Bansal May 02 '11 at 17:14
  • 1
    In your metadata for your Seats object, add [Include] attribute. Edited my code – Scott Silvi May 02 '11 at 17:29
  • OMG finally, it's actually showing the data, so all that was needed was the [Include]!! Thanks so much for bearing with me on this one. +1 on your comment. Thanks again. – Sandeep Bansal May 02 '11 at 17:34
  • No sweat bro. Sorry I missed that. Glad it is working for you. – Scott Silvi May 02 '11 at 17:38