RelationalDbContextOptionsBuilder<TBuilder,TExtension>.TranslateParameterizedCollectionsToParameters Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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.