/// <summary> /// The perform get. /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="IEntityCollection"/>. /// </returns> protected override IEntityCollection PerformGet(Guid key) { var sql = GetBaseQuery(false) .Where(GetBaseWhereClause(), new { Key = key }); var dto = Database.Fetch <EntityCollectionDto>(sql).FirstOrDefault(); if (dto == null) { return(null); } var factory = new EntityCollectionFactory(); var collection = factory.BuildEntity(dto); return(collection); }
/// <summary> /// The perform get all. /// </summary> /// <param name="keys"> /// The keys. /// </param> /// <returns> /// The <see cref="IEnumerable{IEntityCollection}"/>. /// </returns> protected override IEnumerable <IEntityCollection> PerformGetAll(params Guid[] keys) { var dtos = new List <EntityCollectionDto>(); 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 <EntityCollectionDto>(GetBaseQuery(false).WhereIn <EntityCollectionDto>(x => x.Key, keyList, SqlSyntax))); } } else { dtos = Database.Fetch <EntityCollectionDto>(GetBaseQuery(false)); } var factory = new EntityCollectionFactory(); foreach (var dto in dtos) { yield return(factory.BuildEntity(dto)); } //TODO - Keeping original code for now //if (keys.Any()) //{ // foreach (var id in keys) // { // yield return Get(id); // } //} //else //{ // var dtos = Database.Fetch<EntityCollectionDto>(GetBaseQuery(false)); // foreach (var dto in dtos) // { // yield return Get(dto.Key); // } //} }
/// <summary> /// The perform get all. /// </summary> /// <param name="keys"> /// The keys. /// </param> /// <returns> /// The <see cref="IEnumerable{IEntityCollection"/>. /// </returns> protected override IEnumerable <IEntityCollection> PerformGetAll(params Guid[] keys) { if (keys.Any()) { foreach (var id in keys) { yield return(Get(id)); } } else { var factory = new EntityCollectionFactory(); var dtos = Database.Fetch <EntityCollectionDto>(GetBaseQuery(false)); foreach (var dto in dtos) { yield return(factory.BuildEntity(dto)); } } }