Retrieving the first instance of an entity record in a SalesLogix entity repository

I wanted to share a quick little method I found the other day in the Sage.Platform.EntityFactory assembly that allows you to retreive the first instance of a record in a SalesLogix entity repository.

Normally if I wanted to find the first record in a repository I would use something like IRepository and IQueryable like so:

Sage.Entity.Interfaces.ITicket tik = null;
Sage.Platform.RepositoryHelper<Sage.Entity.Interfaces.ITicket> repository =
Sage.Platform.Repository.ICriteria criteria = repository.CreateCriteria();
criteria.Add(repository.EF.Eq(“Issue”,”A big problem”)));
System.Collections.Generic.IList<Sage.Entity.Interfaces.ITicket> ticket = criteria.List<Sage.Entity.Interfaces.ITicket>();
foreach (ITicket ticket in tickets)
    tik = ticket;

There is an easier way to do this however by using code such as this:

Sage.Entity.Interfaces.ITicket tik = Sage.Platform.EntityFactory.GetRepository<Sage.Entity.Interfaces.ITicket>().FindFirstByProperty(“Issue”, “A big problem”);

 A little less code for the same thing.  The only thing here is that you can not sort the results to get a particular record returned if there is more than one potential match.


Kris Halsrud

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

1 Comment

  1. Your post was a great reminder for me today about this technique – thanks for posting Kris!


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!