文档菜单
文档首页
/
MongoDB C# 分析器
/

分析构建器表达式

本页内容

  • 概述
  • 翻译为 MongoDB 查询 API
  • 在 Visual Studio 中分析构建器
  • 简单构建器表达式
  • 跟踪构建器变量
  • 流畅 API

构建器是.NET/C#驱动程序提供的一个类,用于帮助您构建常见的操作,如查询和更新。

要了解有关构建器的更多信息,请参阅使用构建器执行操作,该操作位于.NET/C#驱动程序文档中。

使用C#分析器将您的构建器表达式转换为MongoDB查询API。点击以下选项卡,查看构建器表达式及其对应的MongoDB查询API转换示例

var filter = Builders<Book>.Filter.Eq(b => b.Genre, genre) &
Builders<Book>.Filter.Gte(b => b.Price, minPrice) &
Builders<Book>.Filter.Regex(b => b.Title, titleSearchTerm);
{
"$and": [ { "Genre": genre },
{ "Price": { "$gte": minPrice } },
{ "Title": /titleSearchTerm/ } ]
}

注意

变量名

C#分析器生成的MongoDB查询API转换包含来自您的.NET/C#驱动程序代码的变量名。.NET/C#驱动程序在您的应用程序与MongoDB通信时,用这些变量名的对应值替换它们。

要在Visual Studio中分析您的构建器表达式,请执行以下操作

  1. 按照以下指南安装C#分析器安装指南。

  2. 使用.NET/C#驱动程序编写构建器表达式

  3. 将鼠标移至...注释下您的构建器表达式的第一个方法,以显示包含MongoDB查询API转换的信息消息。

点击以下相应的标签以查看带有或不带信息消息的构建器表达式

Screenshot of builder expression with an ellipsis annotation in Visual Studio.
Screenshot of builder expression with an information message displayed in Visual Studio.

C# 分析器支持构建器变量跟踪和组合。您可以使用 逻辑运算符 将多个构建器表达式组合在一起,并在信息消息中查看 MongoDB 查询 API 的翻译。

点击以下相应的标签以查看带有或不带信息消息的合成构建器变量

Screenshot of builder variable with an ellipsis annotation in Visual Studio.
Screenshot of builder variable with an information message displayed in Visual Studio.

C# 分析器支持使用.NET/C# 驱动程序中的构建器类来实现Fluent API。您可以通过链式构建器方法创建一系列操作,并在信息消息中查看MongoDB查询API的转换。

点击以下相应的选项卡,查看使用链式构建器方法进行的操作,其中是否显示信息消息

Screenshot of Fluent API with an ellipsis annotation in Visual Studio.
Screenshot of Fluent API with an information message displayed in Visual Studio.

提示

错误列表面板

如果您正在使用Windows上的Visual Studio,您可以在错误列表窗口中查看来自{+product+-short}的输出。

有关更多信息,请参阅错误列表窗口,来自Microsoft。

返回

分析您的代码