コード例 #1
0
        public Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate)
        {
            try
            {
                using (var conn = GetDbConnection())
                {
                    predicate = _softDeleteQueryFilter.ExecuteFilter <TEntity, TPrimaryKey>(predicate);
                    var pg = predicate.ToPredicateGroup <TEntity, TPrimaryKey>();
                    return(Task.FromResult(conn.GetList <TEntity>(pg).FirstOrDefault()));
                }
            }
            catch (Exception ex)
            {
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(ex.Message, ex);
                }

                throw new DataAccessException(ex.Message, ex);
            }
        }
コード例 #2
0
        public async Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate)
        {
            try
            {
                if (CPlatformAppConfig.CacheSectionOptions.IsEnableRepositoryCache)
                {
                    var list = await GetAllAsync();

                    return(list.AsQueryable().FirstOrDefault(predicate));
                }
                else
                {
                    using (var conn = GetDbConnection())
                    {
                        predicate = _softDeleteQueryFilter.ExecuteFilter <TEntity, TPrimaryKey>(predicate);
                        var pg = predicate.ToPredicateGroup <TEntity, TPrimaryKey>();
                        return(conn.GetList <TEntity>(pg).FirstOrDefault());
                    }
                }
            }
            catch (Exception ex)
            {
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(ex.Message, ex);
                }

                throw new DataAccessException(ex.Message, ex);
            }
        }
コード例 #3
0
        public async Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate, bool dataPermission = true)
        {
            try
            {
                using (var conn = GetDbConnection())
                {
                    if (conn.State != System.Data.ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    predicate = _softDeleteQueryFilter.ExecuteFilter <TEntity, TPrimaryKey>(predicate);
                    if (dataPermission)
                    {
                        predicate = _orgQueryFilter.ExecuteFilter <TEntity, TPrimaryKey>(predicate);
                    }

                    var pg     = predicate.ToPredicateGroup <TEntity, TPrimaryKey>();
                    var result = conn.GetList <TEntity>(pg).FirstOrDefault();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                if (_logger.IsEnabled(LogLevel.Error))
                {
                    _logger.LogError(ex.Message, ex);
                }

                throw new DataAccessException(ex.Message, ex);
            }
        }