Distinct on multiple properties in a collection

Problem:
How do I get distinct members of a collection, based on multiple properties?

Solution:
Use MoreLinq to get distinct members of a collection, based on multiple properties.
eg: For our application, each member in the household was supposed to have a unique combination of driver’s licence number and driver’s state.

 
var query = household.DistinctBy(
            counter => new { counter.DriverLicenceNumber, counter.DriverLicenceState });
Continue Reading

Performance Improvement for very important client

This data is for all our clients that use our application. Based on the data below there is a significant performance improvement in the application performance in the latest release. Please see highlighted area below. The latest release took place on March 2016.

March2016PerformanceImprovement

One of our biggest clients was threatening to leave us for another provider. Its users were experiencing very long load times(more than a minute in some cases), timeouts etc. I profiled the application using JetBrains DotTrace. All the hotspots in the profiler trace pointed to a very complex stored procedure being called again and again in the application. Since the stored procedure was very complex and used by several other applications it was decided to not change it. Instead we decided to store the results of this stored procedure in session. This lead to the dramatic performance improvement as shown above.

    using System.Web;
    public class RentableItemsStrategy
    {
        public RentableItemsStrategy()
        {
        }

        public RentableTypes Get(int unitId, string dateNeeded, int leaseId)
        {
            var keyTemp = Key(unitId, dateNeeded, leaseId);
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return null;
            }
            
            var rentableTypesForUnitIdDateNeededLeaseId = HttpContext.Current.Session[keyTemp] as RentableTypes;
            if (rentableTypesForUnitIdDateNeededLeaseId != null)
            {
                return rentableTypesForUnitIdDateNeededLeaseId;
            }
            
            var xmlNode = new ServiceAgent.ResidentSvc().GetRentableItems(unitId, dateNeeded, leaseId);
            var rentableTypes = RentableTypes.FromXml(xmlNode);
            HttpContext.Current.Session[keyTemp] = rentableTypes;
            return rentableTypes;
        }

        private string Key(int unitId, string dateNeeded, int leaseId)
        {
            return string.Format("RentableTypes-{0}-{1}-{2}", unitId, dateNeeded, leaseId);
        }
    }
Continue Reading