Share via


RelationalDbContextOptionsBuilder<TBuilder,TExtension>.TranslateParameterizedCollectionsToConstants Method

Definition

Configures the context to translate parameterized collections to inline constants.

public virtual TBuilder TranslateParameterizedCollectionsToConstants ();
abstract member TranslateParameterizedCollectionsToConstants : unit -> 'Builder
override this.TranslateParameterizedCollectionsToConstants : unit -> 'Builder
Public Overridable Function TranslateParameterizedCollectionsToConstants () As TBuilder

Returns

TBuilder

Remarks

When a LINQ query contains a parameterized collection, by default EF Core parameterizes the entire collection as a single SQL parameter, if possible. For example, on SQL Server, the LINQ query Where(b => ids.Contains(b.Id) is translated to WHERE [b].[Id] IN (SELECT [i].[value] FROM OPENJSON(@__ids_0) ...). While this helps with query plan caching, it can produce worse query plans for certain query types.

TranslateParameterizedCollectionsToConstants() instructs EF to translate the collection to a set of constants: WHERE [b].[Id] IN (1, 2, 3). This can produce better query plans for certain query types, but can also lead to query plan bloat.

Note that it's possible to cause EF to translate a specific collection in a specific query to constants by wrapping the parameterized collection in Constant<T>(T): Where(b => EF.Constant(ids).Contains(b.Id). This overrides the default. Likewise, you can translate a specific collection in a specific query to a single parameter by wrapping the parameterized collection in Parameter<T>(T): Where(b => EF.Parameter(ids).Contains(b.Id). This overrides the TranslateParameterizedCollectionsToConstants() setting.

Applies to