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.