Sorting a SalesLogix entity collection using Linq

The SalesLogix entity model offers the ability to access collections of related entities, such as Contacts belonging to an Account.  When you access the collection properties there is no sort order defined so the results can be less than desirable.  You can use ICriteria and define your Order explicitly but that gets to be a bit of code and you cant work directly with the entity collection.

You can easily add a sort to the built in entity collections by using the power of Linq.

You will need to first make sure you include a using statement for Linq:

using System.Linq;

Then you can simply retrieve your collection from the entity and add a sort all in one line.  To add an ascending sort:

Sage.Entity.Interfaces.IAccount account = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;

account.Contacts.OrderBy(x => x.CreateDate);

To add a descending sort:

Sage.Entity.Interfaces.IAccount account = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;

account.Contacts.OrderByDescending(x => x.CreateDate);

The sort field in my examples is the Contact’s CreateDate property.

There you go.  Easy.

ABOUT THE AUTHOR

Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!