How to translate this SQL to LLBLGEN

Posts   
 
    
jmcjq2
User
Posts: 26
Joined: 17-Nov-2009
# Posted on: 27-Aug-2010 07:58:37   

Hi guys,

I have a Gridview that uses this method as the data source:


[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public EntityCollection<EventEntity> GetBySearch()
        {
            EntityCollection<EventEntity> output = new EntityCollection<EventEntity>();
            
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
        
            bucket.Relations.Add(EventEntity.Relations.LookupCodeEntityUsingLocationId, "Location");
            bucket.Relations.Add(EventEntity.Relations.LookupCodeEntityUsingEventTypeId, "EventType");
            
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                 adapter.FetchEntityCollection(output, bucket, 0);
            }

            return output;

        }


I'm not sure if its equivalent to this SQL with regards to the Lookup table(s) relations:


SELECT   dbo.Event.EventId, dbo.Event.LocationId, Location.CodeValue AS Location, dbo.Event.EventTypeId, EventType.CodeValue AS EventType, 
                      dbo.Event.EventDescription, dbo.Event.EventDate, dbo.Event.ProviderName, dbo.Event.EventStatusId
FROM         dbo.Event INNER JOIN
                      dbo.LookupCode AS Location ON dbo.Event.LocationId = Location.LookupCodeId INNER JOIN
                      dbo.LookupCode AS EventType ON dbo.Event.EventTypeId = EventType.LookupCodeId

In the Grid Columns i have something like this to bind the values:


<telerik:GridBoundColumn HtmlEncode="true" DataField="EventType.CodeValue" SortExpression="EventType" HeaderText="Event Type"/>
            <telerik:GridBoundColumn HtmlEncode="true" DataField="Location.CodeValue" SortExpression="Location" HeaderText="Location"/>


The gridview works and displays data but i'm the "CodeValue" column is empty. I'm not sure if i'm defining the "DataField" incorrectly in the gridview or if i'm missing a step in the "GetBySearch" method. Please advise.

Thanks in Advance, John

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Aug-2010 09:29:15   

Relations are only used for filtering. So your code will only fetch Event entities.

You need to use PrefetchPaths to fetch related entities.

jmcjq2
User
Posts: 26
Joined: 17-Nov-2009
# Posted on: 27-Aug-2010 10:30:47   

Walaa wrote:

Relations are only used for filtering. So your code will only fetch Event entities.

You need to use PrefetchPaths to fetch related entities.

Thanks very much, got it too work!