/// <summary> /// Initializes a new instance of the <see cref="AggregationService"/> class. /// </summary> /// <param name="locationService">The location service.</param> /// <param name="userService">The user service.</param> public AggregationService(LocationService locationService, UserService userService) : base() { this.LocationService = locationService; this.UserService = userService; Mappings = new List <MappingAggregator> { MappingAggregator.Init <AggregationModel, AggregationService>(x => x.User, x => x.UserService), MappingAggregator.Init <AggregationModel, AggregationService>(x => x.Locations, x => x.LocationService), }; }
/// <summary> /// Gets the order by expression. /// </summary> /// <param name="map">The map.</param> /// <param name="propertyServiceName">Name of the property service.</param> /// <returns></returns> private dynamic GetOrderByExpression(MappingAggregator map, string propertyServiceName = null) { var service = GetType().GetProperty(map.EntityMember.Member.Name).GetValue(this); var serviceMappings = service.GetType().GetProperty(nameof(ServiceBase.Mappings)).GetValue(service) as List <Mapping>; var serviceMapping = serviceMappings.First(); if (!string.IsNullOrEmpty(propertyServiceName)) { serviceMapping = serviceMappings.Single(x => x.ModelMember.Member.Name == propertyServiceName); } var propertyService = map.AttachedQuery.ElementType.GetProperty(serviceMapping.EntityMember.Member.Name); var parameter = Expression.Parameter(typeof(TJoinResult)); var leftMember = Expression.MakeMemberAccess(parameter, typeof(TJoinResult).GetProperty(map.ModelMember.Member.Name)); var rightMember = Expression.MakeMemberAccess(leftMember, propertyService); return((dynamic)Expression.Lambda(rightMember, parameter)); }