Beispiel #1
0
        /// <summary>
        /// Returns a single entity matching the filter provided
        /// </summary>
        /// <param name="filter">The Expression used to filter objects from the data store</param>
        /// <returns>RepositoryResultList</returns>
        public RepositoryResultSingle <T> Single(Expression <Func <T, bool> > filter)
        {
            RepositoryResultSingle <T> result = new RepositoryResultSingle <T>();

            try
            {
                result.Entity   = _ctx.Set <T>().SingleOrDefault(filter);
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                //  LogError(ex);
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a single entity matching the filter provided
        /// </summary>
        /// <param name="filter">The Expression used to filter objects from the data store</param>
        /// <param name="includes">a parameter list of property names to include in each item in the returned entity object graph</param>
        /// <returns>RepositoryResultList</returns>
        public RepositoryResultSingle <T> Single(Expression <Func <T, bool> > filter, params string[] includes)
        {
            RepositoryResultSingle <T> result = new RepositoryResultSingle <T>();

            try
            {
                var query = _ctx.Set <T>().Where(t => true);
                foreach (string include in includes)
                {
                    query = query.Include(include);
                }
                result.Entity = query.SingleOrDefault(filter.Compile());

                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                //  LogError(ex);
                result.NoErrors = false;
                result.Message  = ex.GetBaseException().Message;
            }

            return(result);
        }