> This page location: /docs.md > /docs/tools-and-connectors.md > /docs/mongodb-analyzer.md > /docs/mongodb-analyzer/current/analyze-code.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: linq, query-api-linq, without-message-method-syntax, with-message-method-syntax, without-message-query-syntax, with-message-query-syntax, code-snippet-linq3, warning-linq3
-->

# Analyze LINQ Expressions

## Overview

**LINQ** is a query syntax included in the C# language. The .NET/C# driver can translate a subset of LINQ expressions into MongoDB aggregation pipelines.

To learn more about LINQ, see the following resources:

- [LINQ](https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/linq/) in the .NET/C# driver documentation

- [LINQ](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/) in the Microsoft C# guide

To learn more about aggregation pipelines, see [Aggregation](https://www.mongodb.com/docs/manual/aggregation/) in the MongoDB manual.

**Note: Runtime Differences**

Although the MongoDB Query API translations generated by the C# Analyzer have the same [query shape](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-query-shape) as your runtime .NET/C# driver queries, there may be slight differences due to the following factors:

- Your Serialization Settings

- Your LINQ Settings

The difference between the translations the C# Analyzer generates and your queries at runtime should not impact your ability to analyze and debug your code.

To learn more about serialization and LINQ settings, see the [FAQ](https://www.mongodb.com/docs/mongodb-analyzer/current/faq.md#std-label-mongodb-analyzer-faq-custom-serialization) page.

Use the C# Analyzer to learn the following about your LINQ expressions:

- How your LINQ expressions translate into the MongoDB Query API

- If any of your LINQ expressions are not supported

## Translate into the MongoDB Query API

Click the following tabs to see an example of a LINQ expression and its corresponding MongoDB Query API translation:

### LINQ

```csharp
var books = queryableCollection
       .Where(b =>
           b.Genre == genre &&
           b.Price >= minPrice &&
           b.Title.Contains(titleSearchTerm))
       .OrderBy(b => b.Price)
       .ToList();
```

**Note: Variable Names**

The MongoDB Query API translations generated by the C# Analyzer contain variable names from your .NET/C# driver code. The .NET/C# driver replaces these variable names with their corresponding values when your application communicates with MongoDB.

## Analyze LINQ in Visual Studio

To analyze your LINQ expressions in Visual Studio, perform the following actions:

1. Install the C# Analyzer as described in the [Install](https://www.mongodb.com/docs/mongodb-analyzer/current/install.md#std-label-mongodb-analyzer-install) guide.

2. Write a LINQ expression with the .NET/C# driver.

3. Move your mouse over the ... annotation beneath the first method of your LINQ expression to display an information message that contains the MongoDB Query API translation.

### Simple LINQ Expressions

The C# Analyzer analyzes LINQ expressions in the following syntax types:

- Method syntax

- Query syntax

Click on the following corresponding tab to see a LINQ expression written in method syntax with or without an information message displayed:

### Without Information Message

![Screenshot of LINQ expression with an ellipsis annotation in Visual Studio.](/_includes/images/linq.png)

Click on the following corresponding tab to see a LINQ expression written in query syntax with or without an information message displayed:

### Without Information Message

![Screenshot of LINQ expression with an ellipsis annotation in Visual Studio.](/_includes/images/linq-query.png)

### Unsupported LINQ Expressions

If your LINQ expression is not supported, the C# Analyzer outputs a `MALinq2001` warning.

The following code snippet contains the unsupported `GetHashCode` LINQ expression:

```csharp
var result = queryableColl.Where(b => b.GetHashCode() == 167);
```

The C# Analyzer shows an annotation on the unsupported expression and generates the following warning message:

```text
Expression not supported: b.GetHashCode().
```

The following screenshot shows the annotated code and the warning displayed when you hover over the annotation:

![Screenshot of warning displayed in Visual Studio from unsupported LINQ.](/_includes/images/linq-unsupported-popup.png)

**Tip: Error List Panel**

If you are using Visual Studio for Windows, you can view the output from the C# Analyzer in the Error List window.

To learn more, see [Error List Window](https://docs.microsoft.com/en-us/visualstudio/ide/reference/error-list-window?view=vs-2022) from Microsoft.

To view more examples of unsupported LINQ expressions, see the [MongoDB C# Analyzer Github repository.](https://github.com/mongodb/mongo-csharp-analyzer/blob/main/tests/MongoDB.Analyzer.Tests.Common.TestCases/Linq/NotSupportedLinqExpressions.cs)

### Analyze LINQ3

To analyze a LINQ3 expression, you must configure the C# Analyzer to use the LINQ3 provider. To learn how to configure your LINQ provider, see the [configuration](https://www.mongodb.com/docs/mongodb-analyzer/current/configuration.md#std-label-mongodb-analyzer-configuration) guide.

**Important: Expressions Supported Only by LINQ3**

If your .NET/C# driver version supports LINQ3 but you configure your C# Analyzer to use the default LINQ provider (LINQ2), the C# Analyzer informs you if your LINQ expression is supported by LINQ3 but not LINQ2.

Click the tabs to see a LINQ expression supported by LINQ3 but not LINQ2 and the corresponding warning output by the C# Analyzer:

### Code Snippet

```csharp
var result = queryableColl.Where(b => b.Title.Substring(0) == "Pane");
```

To view examples of expressions the .NET/C# driver only supports with the LINQ3 provider, see the [MongoDB C# Analyzer Github repository.](https://github.com/mongodb/mongo-csharp-analyzer/blob/v1.5.0/tests/MongoDB.Analyzer.Tests.Common.TestCases/Linq/NotSupportedLinq2.cs)
