以字符串形式获取表达式的值

I'm working on a generic repository for Entity Framework. To search for values I have a Find method on my repository that takes an expression. During this process I want to log the expression. I do this by getting expression.Body.

这是我的代码

    public async Task<TEntity> FindFirstOrDefault<TEntity>(Expression<Func<TEntity, bool>> expression) where TEntity : class
    {
        string expBody = expression.Body.ToString();

        // Log expBody here

        return await _context.Set<TEntity>().Where(expression).FirstOrDefaultAsync().ConfigureAwait(false);
    }

当在像这样的硬编码条件下进行测试时,以上代码可以正常工作。

var blogs = await uow.Repository.FindFirstOrDefault<Blog>(x => x.BlogId == 1).ConfigureAwait(false);

When I debug that above line has expBody with a value of (x.BlogId == 1)

但是,如果我对这样的变量进行比较:

int id = 1;
var blogs = await uow.Repository.FindFirstOrDefault<Blog>(x => x.BlogId == id).ConfigureAwait(false);

I end up getting this for expBody:

(x.BlogId == value(TestProject.ValueService+<>c__DisplayClass4_0).intId)

当我实际引用变量时,如何像使用硬编码值时那样获得实际的表达式主体?