Which are some websites similar to LingQ

Use LINQ to build a query

  • 3 minutes to read

Note

Valid from November 2020:

  • Common Data Service has been renamed Microsoft Dataverse. additional Information
  • Updated some terms in Microsoft Dataverse. For example is entity now table and field is now column. additional Information

This article will be updated shortly to reflect the latest terminology.

The .NET Language-Integrated Query (LINQ) query provider in Microsoft Dataverse uses standard LINQ syntax. The first step in building a LINQ query is to identify the relevant entity types and the relationships between them. You can then specify the data source and the other query parameters.

The clause is used to return a single "root" entity. The query provider can only return entities of a single entity type. and clauses must refer to this root entity. With clauses you can add entities to a relationship to the "root" entity.

LINQ operators

All LINQ query expressions have a similar format. The following table lists the most common clauses in a LINQ query expression when using the Dataverse LINQ query provider.

from

If you are using the generated service context and legacy binding, use the entity set such as B., in the generated context.

If you are not using a generated context, you can use the method in the organization's service context to access Dataverse entities.

Example:

Using the generated service context:

Using the method:

join

The clause is an inner join. Use the clause to work with two or more entities that can be joined with a common attribute value.

Example:

The following applies:

The clause applies a filter to the results. A Boolean expression is often used for this. The filter indicates which elements are to be excluded from the source order. Each clause can only contain conditions for a single entity type. A compound condition involving multiple entities is invalid. Instead, each entity should be filtered in separate clauses.

Example:

orderby

The operator puts the returned query attributes in a specific order.

Example:

Choose

The clause defines the form of the data returned. The clause creates a set of columns based on the query expression results. You can also define an instance of a new object to work with. The new object created with the clause is not created on the server, but is a local instance.

Example:

LINQ restrictions

The LINQ query provider supports a subset of the LINQ operators. Not all conditions that can be expressed in LINQ are supported. The following table lists some restrictions on the basic LINQ operators.

LINQ operatorrestrictions
Represents an inner or outer link. Only left outer links are supported.
Supports a single clause per query.
The left side of the clause must have an attribute name and the right side of the clause must have a value. You cannot set the left side to be a constant. There can be no constants on both sides of the clause.

Supports the functions,, and.
Unsupported. FetchXML supports grouping options that are not available using the LINQ query provider. More information: Using FetchXML Aggregation
Supports sorting by entity attributes such as.
Supports anonymous types, constructors, and initializers.
The operator is not supported.
and Supported and with server-side paging. The value must be greater than or equal to the value.
Unsupported. FetchXML supports aggregation of options that are not available using the LINQ query provider. More information: Using FetchXML Aggregation

Filtering multiple entities

You can use .NET Language-Integrated Query (LINQ) to build complex queries in Dataverse. You can use multiple clauses with filter clauses to get a result that is filtered on attributes from multiple entities.

The following example shows how to create a LINQ query that works with two entities and filters the result based on values ​​from each entity.

See also

Example: building a LINQ query
Example: LINQ query examples
Building queries with LINQ (.NET Language Integrated Query)
Using late-bound entity classes with a LINQ query
Blog: LINQPad 4 Drivers for Dynamics CRM REST / Web-API are available on CodePlex