Condividi tramite


RelationalDbContextOptionsBuilder<TBuilder,TExtension>.TranslateParameterizedCollectionsToParameters Method

Definition

Configures the context to translate parameterized collections to parameters.

public virtual TBuilder TranslateParameterizedCollectionsToParameters ();
abstract member TranslateParameterizedCollectionsToParameters : unit -> 'Builder
override this.TranslateParameterizedCollectionsToParameters : unit -> 'Builder
Public Overridable Function TranslateParameterizedCollectionsToParameters () 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.

TranslateParameterizedCollectionsToParameters() explicitly instructs EF to perform the default translation of parameterized collections, which is translating them to parameters.

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.

Applies to