Sort 2 Columns

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 15-Apr-2013 10:24:50   

LLBLGEN 4.0 Mysql 5 LLBLGEN Runtime Framework C# Windows App.

Hi I need to sort 2 columns in the following way.

I need to sort by CreatedDate and ModifiedDate and fetch latest ONE record based on recent date which can be either CreatedDate OR ModifiedDate. Not sure how can i achieve this and what to alter in the following code.

            DtableTitle.Clear();
            var title = new TitleCollection();
            Sort.Add(TitleFields.Createddate | SortOperator.Descending);
            Sort.Add(TitleFields.Modifieddate | SortOperator.Descending);
            title.GetMulti(null, 1, Sort, null, null, null, 0, 0);
            var titleprojection =
                EntityFields.ConvertToProjectors(title.EntityFactoryToUse.CreateFields());
            title.DefaultView.CreateProjection(titleprojection, DtableTitle);
            return DtableTitle;
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Apr-2013 21:03:30   

If you can come up with the plain SQL you want to execute we can help you formulate it with code.

But if I understand your case correctly, I think your goal can be easily achieved solved by a simple business logic tweak.

In a similar system I used to work in, when a newly record is created, both CreatedDate and ModifiedDate are set to the same value. Afterwards, only ModifiedDate is updated.

This way you can only think of sorting on one field: ModifiedDate.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 16-Apr-2013 10:49:23   

OK