table relations and binding related values to a grid

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 07-Jan-2008 18:44:06   

Hello

I am having problems with my code. I am calling back an entity collection and binding the returned values to a grid, but I am doing something wrong somewhere and can't work out what!

my code:


  public static EntityCollection GetQuotes(Guid userId)
        {
            EntityCollection Quotes = new EntityCollection(new OrderDetailEntityFactory());
            SortExpression sorter = new SortExpression(OrderFields.OrderDate | SortOperator.Ascending);

            IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.OrderDetailEntity);
                    
            prefetchPath.Add(OrderDetailEntity.PrefetchPathPriceQuotes);
            prefetchPath.Add(OrderDetailEntity.PrefetchPathOrder);
            prefetchPath.Add(OrderDetailEntity.PrefetchPathProduct);

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            
            bucket.Relations.Add(OrderDetailEntity.Relations.PriceQuotesEntityUsingOrderDetailId);
            bucket.Relations.Add(OrderDetailEntity.Relations.OrderEntityUsingOrderId);
            bucket.Relations.Add(OrderDetailEntity.Relations.ProductEntityUsingProductId);

            bucket.PredicateExpression.Add(OrderFields.UserId  == userId);
            bucket.PredicateExpression.AddWithAnd(OrderFields.AwaitingQuote == false);
            bucket.PredicateExpression.AddWithAnd(PriceQuotesFields.Approved == DBNull.Value);
    
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(Quotes, bucket, 0, sorter, prefetchPath);
            }

            return Quotes;
        }

my grid

<radG:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
        EnableAJAX="true" PageSize="10" AllowMultiRowSelection="true">
        <MasterTableView DataKeyNames="OrderDetailId">
            <Columns>
                <radG:GridTemplateColumn>
                    <ItemTemplate>
                        <a href="javascript:openWindow('<%#DataBinder.Eval(Container.DataItem,"OrderDetailId") %>')">
                            view</a>
                    </ItemTemplate>
                </radG:GridTemplateColumn>
                <radG:GridBoundColumn DataField="OrderDetailId" UniqueName="OrderDetailId" Visible="false">
                </radG:GridBoundColumn>
                <radG:GridBoundColumn DataField="Order.OrderDate" HeaderText="Order Date" UniqueName="OrderDate"
                    ReadOnly="true">
                </radG:GridBoundColumn>
                        <radG:GridBoundColumn DataField="Product.Name" HeaderText="Product" ReadOnly="true"
                    UniqueName="ProductName">
                </radG:GridBoundColumn>
                <radG:GridBoundColumn DataField="NumberOfPages" HeaderText="Pages" ReadOnly="true"
                    UniqueName="Pages" />
                <radG:GridBoundColumn DataField="Quantity" HeaderText="Quantity" ReadOnly="true"
                    UniqueName="Quantity">
                </radG:GridBoundColumn>
                  <radG:GridBoundColumn DataField="PriceQuotes.Quote" HeaderText="Quote" ReadOnly="true"
                    UniqueName="Quote" />
            </Columns>
    
        </MasterTableView>
    </radG:RadGrid>

Everything is bound to the grid except pricequotes.quote, it doesn't appear to be in my entity collection. I have 4 tables I am using whos basic layout and columsn are as follows

Order OrderId (PK) OrderDate UserID ... OrderDetail orderDetailID (PK) ProductID(FK) OrderID(FK) NumberOfPages Quantity ... Product ProductID(PK) ProductName ProductDetails ... and PriceQuotes PriceQuoteID(PK) OrderDetailID(FK) Quote Date ..

What am I doing wrong? It is not crashing, I am just getting the "OrderDetailEntity.Entity ..." in my PriceQuotes.Quote column returned Thanks

Bex

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 07-Jan-2008 19:19:18   

Hi,

did you debug the grid to check the actual values of:

  • PriceQuotes and
  • PriceQuotes.Quote?

Just to make sure you're not just having a typo or other issue on a lower level than the bouding to the grid.

Gab.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 07-Jan-2008 19:25:00   

i'm not fimilar with radG controls, but i assume this is a 3rd party gui control. with standard gridviews you cannot bind to complex objects using declaritive syntax. instead you may need to cast the value and bind. this can be done in either the markup or code behind.


<radG:GridTemplateColumn HeaderText="Quote" ReadOnly="true" UniqueName="Quote" >
    <ItemTemplate>
          <%# ((EntityCollection<PriceQuotesEntity>)Eval("PriceQuotes"))[0].Quote %>
    </ItemTemplate>
</radG:GridTemplateColumn>

or


<radG:GridTemplateColumn HeaderText="Quote" ReadOnly="true" UniqueName="Quote" >
    <ItemTemplate>
          <asp:Label ID="QuoteLabel" runat="server" />
    </ItemTemplate>
</radG:GridTemplateColumn>


protected override OnInit(EventArgs e)
{
      base.OnInit(e);
      RadGrid1.OnRowDataBound += RowDataBound;
}

private void RowDataBound(object sender e, RadGridViewRowDataBoundEventArgs e)
{
      if(e.Row.RowIndex > -1)
      {
            OrderDetailEntity detail = e.Row.DataItem as OrderDetailEntity;
            double quote = detail.PriceQuotes[0].Quote;
(           (Label)e.Row.FindControl("QuoteLabel")).Text = quote.ToString();
      }
}

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 08-Jan-2008 09:59:39   

Thanks!! That works a treat! smile

jmeckley wrote:

i'm not fimilar with radG controls, but i assume this is a 3rd party gui control. with standard gridviews you cannot bind to complex objects using declaritive syntax. instead you may need to cast the value and bind. this can be done in either the markup or code behind.


<radG:GridTemplateColumn HeaderText="Quote" ReadOnly="true" UniqueName="Quote" >
    <ItemTemplate>
          <%# ((EntityCollection<PriceQuotesEntity>)Eval("PriceQuotes"))[0].Quote %>
    </ItemTemplate>
</radG:GridTemplateColumn>

or


<radG:GridTemplateColumn HeaderText="Quote" ReadOnly="true" UniqueName="Quote" >
    <ItemTemplate>
          <asp:Label ID="QuoteLabel" runat="server" />
    </ItemTemplate>
</radG:GridTemplateColumn>


protected override OnInit(EventArgs e)
{
      base.OnInit(e);
      RadGrid1.OnRowDataBound += RowDataBound;
}

private void RowDataBound(object sender e, RadGridViewRowDataBoundEventArgs e)
{
      if(e.Row.RowIndex > -1)
      {
            OrderDetailEntity detail = e.Row.DataItem as OrderDetailEntity;
            double quote = detail.PriceQuotes[0].Quote;
(           (Label)e.Row.FindControl("QuoteLabel")).Text = quote.ToString();
      }
}