/// <summary> /// The perform get all operation. /// </summary> /// <param name="keys"> /// The keys. /// </param> /// <returns> /// The collection of all <see cref="ICustomer"/>. /// </returns> protected override IEnumerable <ICustomer> PerformGetAll(params Guid[] keys) { var dtos = new List <CustomerDto>(); if (keys.Any()) { // This is to get around the WhereIn max limit of 2100 parameters and to help with performance of each WhereIn query var keyLists = keys.Split(400).ToList(); // Loop the split keys and get them foreach (var keyList in keyLists) { dtos.AddRange(Database.Fetch <CustomerDto, CustomerIndexDto>(GetBaseQuery(false).WhereIn <CustomerDto>(x => x.Key, keyList, SqlSyntax))); } } else { dtos = Database.Fetch <CustomerDto, CustomerIndexDto>(GetBaseQuery(false)); } var factory = new CustomerFactory(); foreach (var dto in dtos) { yield return(factory.BuildEntity(dto, _customerAddressRepository.GetByCustomerKey(dto.Key), GetNotes(dto.Key))); } // TODO - Not sure if the above is correct so keeping original query //if (keys.Any()) //{ // foreach (var key in keys) // { // yield return Get(key); // } //} //else //{ // var factory = new CustomerFactory(); // var dtos = Database.Fetch<CustomerDto, CustomerIndexDto>(GetBaseQuery(false)); // foreach (var dto in dtos) // { // yield return factory.BuildEntity(dto, _customerAddressRepository.GetByCustomerKey(dto.Key), GetNotes(dto.Key)); // } //} }
/// <summary> /// Performs the Get by key operation. /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="ICustomer"/>. /// </returns> protected override ICustomer PerformGet(Guid key) { var sql = GetBaseQuery(false) .Where(GetBaseWhereClause(), new { Key = key }); var dto = Database.Fetch <CustomerDto, CustomerIndexDto>(sql).FirstOrDefault(); if (dto == null) { return(null); } var factory = new CustomerFactory(); var customer = factory.BuildEntity(dto, _customerAddressRepository.GetByCustomerKey(key), GetNotes(key)); return(customer); }
/// <summary> /// The perform get all operation. /// </summary> /// <param name="keys"> /// The keys. /// </param> /// <returns> /// The collection of all <see cref="ICustomer"/>. /// </returns> protected override IEnumerable <ICustomer> PerformGetAll(params Guid[] keys) { if (keys.Any()) { foreach (var key in keys) { yield return(Get(key)); } } else { var factory = new CustomerFactory(); var dtos = Database.Fetch <CustomerDto, CustomerIndexDto>(GetBaseQuery(false)); foreach (var dto in dtos) { yield return(factory.BuildEntity(dto, _customerAddressRepository.GetByCustomerKey(dto.Key), GetNotes(dto.Key))); } } }