Can't Display lookup data on GridView

10 posts, 0 answers
  1. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 23 Jun 2010 Link to this post

    Hello,
    I have tried using [Include] without any luck.
    I am trying to show the EmployeeID, LastName, FirstName (amongst other data in other lookup tables) in a gridview.
    I have attached an image of the a section of the model object.

    (a) is a section of my model - which shows a 1 to many relationship between Employee and Contact.
    The employee table is self-referencing. I have edited the Employees in the Employee entity diagram to be DirectReports and Manager.
    The Contact table can have multiple records for the same EmployeeID - one for the employee themselves and one for each of their other contacts like spouses.

    (b) Section of my metadata class

      internal sealed class EmployeeMetadata 
            { 
     
                // Metadata classes are not meant to be instantiated. 
                private EmployeeMetadata() 
                { 
                } 
                           
                [Include] 
                [Display(Order = 0)] 
                public EntityCollection<Contact> Contacts { get; set; } 

    (c) My GetEmployee procedure

       public IQueryable<Employee> GetEmployees() 
            { 
                return this.ObjectContext.Employees.Include("Contacts").Where(e => e.CurrentFlag == true).OrderBy(e => e.EmployeeID);  
            } 

    (d) My DDS declaration
    <riaControls:DomainDataSource AutoLoad="True"  Height="0" LoadedData="EmployeeDDS_LoadedData"   d:DesignData="{d:DesignInstance domain:Employee, CreateList=true}"  
                                                        Name="EmployeeDDS" QueryName="GetEmployeesQuery" Width="0" > 
                                                                          <riaControls:DomainDataSource.DomainContext> 
                                                                                    <domain:hrContext /> 
                                                                            </riaControls:DomainDataSource.DomainContext> 
       </riaControls:DomainDataSource> 

    (e) and finally, my gridview declaration
     <telerik:RadGridView Name="EmployeeRadGridView"  ItemsSource="{Binding ElementName=EmployeeDDS, Path=Data}"  
                                                                 Width="717" Height="333" AutoGenerateColumns="False" RowHeight="15" FontFamily="Lucida Sans Unicode"   
                                                                   RowLoaded="EmployeeRadGridView_RowLoaded" DataLoading="EmployeeRadGridView_DataLoading"  Background="Azure"  
                                                                 SelectionChanged="EmployeeRadGridView_SelectionChanged"     
                                                                 AlternateRowBackground="LightSteelBlue" > 
                                                
     
                                            <telerik:RadGridView.Columns> 
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=EmployeeID}" Header="EmployeeID" Width="100"
                                                    <telerik:GridViewDataColumn.AggregateFunctions> 
                                                        <telerik:CountFunction Caption="Count:" /> 
                                                    </telerik:GridViewDataColumn.AggregateFunctions> 
                                                </telerik:GridViewDataColumn> 
     
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LastName}" Header="LastName" Width="100" IsReadOnly="True" /> 
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=NationalIDNumber}" Header="NationalIDNumber" Width="100"/>    
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LoginID}" Header="LoginID" Width="100"/>   
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=TitleID}" Header="Title"/> 
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=HireDate}" Header="HireDate" DataFormatString="{}{0:d}" > 
                                                </telerik:GridViewDataColumn> 
     
                                            </telerik:RadGridView.Columns> 
                                                <telerik:RadGridView.ChildTableDefinitions> 
                                                    <telerik:GridViewTableDefinition> 
                                                        <telerik:GridViewTableDefinition.Relation> 
                                                            <telerik:TableRelation IsSelfReference="True"
                                                                <telerik:TableRelation.FieldNames> 
                                                                    <telerik:FieldDescriptorNamePair  
                                                                        ParentFieldDescriptorName="EmployeeID"  
                                                                        ChildFieldDescriptorName="ReportsToID"/> 
                                                                </telerik:TableRelation.FieldNames> 
                                                            </telerik:TableRelation> 
                                                        </telerik:GridViewTableDefinition.Relation> 
                                                    </telerik:GridViewTableDefinition> 
                                                </telerik:RadGridView.ChildTableDefinitions> 
            </telerik:RadGridView> 
     


    Grateful if someone could point out to me what I am missing. This is my 3rd day fighting over this. 
    HOW DO I GET TO SEE THE LASTNAMES AND FIRSTNAMES ON THE GRID???

    Thanks !
    J
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 28 Jun 2010 Link to this post

    Hello jay,

    Probably you stumbled upon the problem described here.

    I have attached a sample VS 2010 solution to this thread as well.

    Sincerely yours,
    Veskoni
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 28 Jun 2010 Link to this post

    Thanks Veskoni.
    The solution did not quite help me. My main aim is to show the LastName (which is taken from an INCLUDED lookup entitiy -Contact) in the GridView alongside EmployeeID, LoginId, HireDate (which come from the main Employee entity).
    I have a normalized database that stores names in only one table - Contact. It would have been easier if the Lasname was a column in the Employee table, but I opted for the current database structure.

    J
  5. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 28 Jun 2010 Link to this post

    Hi Veskoni,

    The attached image shows what I am trying to achieve. 
    In this scenario, Employees 2,4,5,6 & 7 report to Employee 1, and can be seen when I expand the + box at the left. This bit is working great as i can clearly see which employee has direct reports and who they are. My ONLY current need is to populate the LastName column in the header section of the grid.

    How can I modify my code to make LastName, which comes from a Contact lookup entity, show up? As I said earlier, there is a 1 to many relationship between the Employee and Contact entities. For a give record in Employee, there can be several records in Contact, the first of which will have a contactType of 'Self'. Other records can be Spouse, NextofKin...........

    Thanks!
    J

  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Jul 2010 Link to this post

    Hi jay,

    I have updated my project to reflect the things you need. I have a table Orders and another table OrderDetails. I am showing the Max unit price from the Order Details table into the root gridview (which shows the orders).
    Note the Order.cs class which defines the MaxUnitPrice property.

    Hope this helps you achieve the same goal.

    Regards,
    Veskoni
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 01 Jul 2010 Link to this post

    Thanks Veskoni,

    This is very close. Can I assume that it is not possible to databind to the LastName field using something like:

      <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=LastName}" Header="LastName" Width="100" IsReadOnly="True" />   


    OR

     <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Contact.LastName}" Header="LastName" Width="100" IsReadOnly="True" />
    even after specifying the INCLUDE?

    I was able to run your updated app, and see the lookup value in the MaxUnitPrice column. This is great! 
    However, when I tried to sort by MaxUnitPrice I get the following error:  {System.ServiceModel.DomainServices.Client.DomainOperationException: Load operation failed for query 'GetOrders'. The specified type member 'MaxUnitPrice' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.}

    Any suggestions?
    Thanks !
    J


  8. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 01 Jul 2010 Link to this post

    Thanks, Veskoni !
    A suggestion from Pavel fixed it. I am using GridComboboxes.

    Regards,
    J
  9. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2010 Link to this post

    Hello Jay,
    May I ask you how you solved your problem?
    I have almost the same trouble...

    I'm trying to sort on a computer property and this gives me the same error...

    Any hints on that? Tanks...

    using System.Runtime.Serialization;
    namespace AWeb
    {
        public partial class ProgramDetail
        {
            [DataMember]
            public string FormattedShowName
            {
                get
                {
                    if (string.IsNullOrWhiteSpace(this.ShowName))
                    {
                        return this.Title;
                    }
                    else
                    {
                        return string.Format("{0} S{1:00}E{2:00}", this.ShowName, this.Season, this.Episode);
                    }
                }
                set { }
            }
        }
    }
  10. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 03 Sep 2010 Link to this post

    HI John,
    Sorry for replying so late. I just saw your post.

    Please take a look at Pavel's suggestion on July 1st on the this page:
    http://www.telerik.com/community/forums/silverlight/gridview/binding-lookup-values.aspx


    Regards,
    J
  11. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 04 Sep 2010 Link to this post

    Hello Jay,
    Thank you exactly what I needed ;)
Back to Top
DevCraft banner