Beispiel #1
0
        public async Task <TEntity> GetByIdAsync(int id)
        {
            CreateUpdateActions();

            if (Current.Any(p => p.Entity.Id == id))
            {
                return(Current.Single(p => p.Entity.Id == id).Entity);
            }

            string selectByIdQuery = _sqlGeneratorBase.BuildGetByIdSqlCommand(typeof(TEntity), nameof(Entity.Id));

            IEnumerable <TEntity> resultSet = await _connection.QueryAsync <TEntity>(selectByIdQuery, new { Id = id }).ConfigureAwait(false);

            if (!resultSet.Any())
            {
                throw new EntityDoesNotExistsException($"{typeof(TEntity)} does not exist.");
            }

            TEntity entityResult = resultSet.Single();

            IDictionary <string, string> cleanProperties = _dataComparer.ConvertObjectToPropertiesDictionary(entityResult);

            Current.Add(new CleanEntity <TEntity>(entityResult, cleanProperties));

            return(entityResult);
        }