Exemple #1
0
        public RepositoryResultSingle <T> GetObjectByKey(object key)
        {
            RepositoryResultSingle <T> result = new RepositoryResultSingle <T>();

            try
            {
                result.Entity   = this.ctx.Set <T>().Find(key);
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                result.NoErrors = false;
                result.Message  = ex.ToString();
            }

            return(result);
        }
Exemple #2
0
        public RepositoryResultSingle <T> SingleAsNoTracking(Expression <Func <T, bool> > filter)
        {
            RepositoryResultSingle <T> result = new RepositoryResultSingle <T>();

            try
            {
                result.Entity   = ctx.Set <T>().AsNoTracking().SingleOrDefault(filter);
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                result.NoErrors = false;
                result.Message  = ex.ToString();
            }

            return(result);
        }
Exemple #3
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)
            {
                result.NoErrors = false;
                result.Message  = ex.ToString();
            }

            return(result);
        }