Example #1
0
 /// <summary>
 /// Retrieves one or more results, matching the query input. If there are 0 results, throws an exception.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query">The query to run, and retrieve Entities via</param>
 /// <returns></returns>
 /// <exception cref="Wolf.Utility.Core.Exceptions.IncorrectCountException{T}">Thrown when there is 0 results found matching the query</exception>
 private ICollection <T> FindMultipleResults <T>(IQueryable <T> query) where T : class, IEntity
 {
     lock (ContextLock)
     {
         var result = query.ToList();
         if (result.Any())
         {
             return(result);
         }
         throw IncorrectEntityCountException <T> .Constructor(1, result.Count, elements : new List <T>());
     }
 }
Example #2
0
 /// <summary>
 /// Retrieves exactly one result, matching the query input. If there are more or less, throws an exception.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query">The query to run, and retrieve Entities via</param>
 /// <returns></returns>
 /// <exception cref="Wolf.Utility.Core.Exceptions.IncorrectCountException{T}">Thrown when there is less or more than 1 result found matching the query</exception>
 private T FindOneResult <T>(IQueryable <T> query) where T : class, IEntity
 {
     lock (ContextLock)
     {
         var result = query.ToList();
         if (result.Count == 1)
         {
             return(result.First());
         }
         if (result.Count > 1)
         {
             throw IncorrectEntityCountException <T> .Constructor(1, result.Count, true, result);
         }
         throw IncorrectEntityCountException <T> .Constructor(1, result.Count, elements : new List <T>());
     }
 }