WHERE (@CategoryId IS NULL OR CategoryId = @CategoryId)

类似于

WhereIf(!string.IsNullOrEmpty(a), A = a);

相关文章: