Example #1
0
        public async Task <TEntity> GetByIdAsync(object id, CancellationToken cancellationToken, params string[] includePaths)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var lambda = _expressionBuilder.BuildPrimaryKeyExpressionFromModel <TEntity>(_c.Model, id);
            var result = await _c.Set <TEntity>().IncludePaths(includePaths).FirstOrDefaultAsync(lambda, cancellationToken);

            stopWatch.Stop();
            _logger.LogDebug("EfReadRepository.GetByIdAsync for {EntityType} with {IncludePaths} took {ElapsedMilliseconds} ms", typeof(TEntity).Name, string.Join(", ", includePaths), stopWatch.ElapsedMilliseconds);

            return(result);
        }