EntityView sorting on column from 2 tables

Posts   
 
    
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 21-Dec-2007 18:41:08   

I fetch data from 2 tables (Log and LogEvent) into my entity collection (of LogEvents) and sort using data from multiple tables. The sort expression (sort on Log.Date first and LogEvent.Sequence next) works fine on the entity collection.

Then I create a EntityView2 with same sort expression but the view is not sorted right. It sorts only on the LogEvent.Sequence and not the Log.Date field.

ISortExpression logOrder = new SortExpression();
logOrder.Add(LogFields.Date | SortOperator.Ascending);
logOrder.Add(LogEventFields.Sequence | SortOperator.Ascending);
// Fetch the data
m_EventColln = new EntityCollection<DbLogEvent>(new DbLogEventFactory());
adapter.FetchEntityCollection(m_EventColln, relBucket, FETCH_ALL, logOrder, fetchPath);
// Setup the event view with the sorter
m_EventView = new EntityView2<DbLogEvent>(m_EventColln, logOrder);

Is it not possible to sort the view based on both the table columns? Is there a workaround if this is not possible?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Dec-2007 05:01:58   

That's indeed possible. Could you post the complete block of code and the generated SQL code (LLBLGenPro Help - Using generated code - Troubleshooting and debugging) ?

David Elizondo | LLBLGen Support Team
Smoov
User
Posts: 2
Joined: 22-Feb-2008
# Posted on: 23-Feb-2008 00:09:14   

In relation to Koushik view issues i am having the same problem.

Here is the basic code we are using

protected virtual void RefreshEventView() { try { ISortExpression logOrder = GetSortExpression(); m_EventView = m_EventColln.CreateView(); m_EventView.Sorter = logOrder; } catch (System.Exception ex) { RCS.Transport.Logger.LogException(ex, true); } }

Here is the sort Expression being used.. protected virtual ISortExpression GetSortExpression() { try { ISortExpression logOrder = new SortExpression(); logOrder.Add(LogFields.Date | SortOperator.Ascending); logOrder.Add(LogGroupFields.Sequence | SortOperator.Ascending); logOrder.Add(LogEventFields.Sequence | SortOperator.Ascending); logOrder.Add(LogEventFields.SubSequence | SortOperator.Ascending);

            return logOrder;
        }
        catch (System.Exception ex)
        {
            RCS.Transport.Logger.LogException(ex, true);
        }

        return null;
    }

Attached is the graphical UI Binding to the view. In the attachment you can see the collection is sorted by the LogEventField.Sequence and the logGroupFields.Sequence is ignored.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Feb-2008 03:55:50   

We will investigate this ASAP. Could you please provide us the LLBLGenPro version and RuntimeLibraries version you are using?

How the entities (Log, LogEvent, LogGroup) are related (m:1, 1:m)?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39870
Joined: 17-Aug-2003
# Posted on: 25-Feb-2008 10:26:52   

You can't sort an in-memory entity collection on fields in related entities. You can only sort a collection on fields IN the entities inside the entity collection to sort (through the view).

Frans Bouma | Lead developer LLBLGen Pro
Smoov
User
Posts: 2
Joined: 22-Feb-2008
# Posted on: 27-Feb-2008 18:04:19   

Is there any plans to make views work with related fields or it is what it is and we need to sort it ourselfs?

Or is there another way we can do this, A call to the database to resort is not a good idea.

Dustin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39870
Joined: 17-Aug-2003
# Posted on: 27-Feb-2008 18:43:45   

Smoov wrote:

Is there any plans to make views work with related fields or it is what it is and we need to sort it ourselfs?

Or is there another way we can do this, A call to the database to resort is not a good idea.

Dustin

filtering on related fields works since v2.5, sorting doesn't. We're looking into if we should support sorting on related entities, as it could be Linq to Objects in .NET 3.5 offers this feature as well.

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 27-Feb-2008 20:40:16   

We're looking into if we should support sorting on related entities

+1

koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 10-Jul-2008 02:29:18   

Is this feature available now?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2008 05:50:37   

Yes:

// doing a normal fetch with m:1 prefetchPaths
EntityCollection<OrderEntity> orders = new EntityCollection<OrderEntity>(new OrderEntityFactory());
IPrefetchPath2 path = new PrefetchPath2((int)EntityType.OrderEntity);
path.Add(OrderEntity.PrefetchPathCustomer);
path.Add(OrderEntity.PrefetchPathShipper);

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(orders, null, path);
}

// -------------

// in-memory ordering on related entities via Linq
var orderdOrdersByCustomerCompanyName = orders.OrderBy(o => o.Customer.CompanyName);

// show the ordered results
foreach (var v in orderdOrdersByCustomerCompanyName)
{
    Console.WriteLine("{0}\t{1}", v.OrderId, v.Customer.CompanyName);               
}


// ------------

// in-memory ordering on related entities on two fields via Linq
var orderdOrdersByCustomerCompanyNameAndShipperPhone 
    = orders.OrderBy(o => o.Customer.CompanyName).ThenBy(o => o.Shipper.Phone);

// show the ordered results
foreach (var v in orderdOrdersByCustomerCompanyNameAndShipperPhone)
{
    Console.WriteLine("{0}\t{1}\t{2}", v.OrderId, v.Customer.CompanyName, v.Shipper.Phone);
}
David Elizondo | LLBLGen Support Team