Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo ObjectQuery<T>.Intersect (ObjectQuery<T>)

 

Limita i risultati della query includendo solo i risultati presenti in un'altra query di oggetto.

Spazio dei nomi:   System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public ObjectQuery<T> Intersect(
	ObjectQuery<T> query
)

Parametri

query
Type: System.Data.Objects.ObjectQuery<T>

Oggetto ObjectQuery<T> che rappresenta i risultati da includere nella query.

Valore restituito

Type: System.Data.Objects.ObjectQuery<T>

Nuova istanza di ObjectQuery<T> equivalente all'istanza originale con l'operatore INTERSECT applicato in base al parametro query specificato.

Exception Condition
ArgumentNullException

Il parametro query è null oppure una stringa vuota.

The supplied query that defines results to include must be of the same type or of a type that is compatible with the T:System.Data.Objects.ObjectQuery`1.

Parameters that are defined in the supplied query are merged with parameters that are defined in the T:System.Data.Objects.ObjectQuery`1 instance. Parameters must be unique in the combined T:System.Data.Objects.ObjectParameterCollection. There cannot be two parameters in the combined collection with the same name. For more information, see Query Builder Methods.

The resulting query inherits the connection from the T:System.Data.Objects.ObjectQuery`1 instance on which the M:System.Data.Objects.ObjectQuery`1.Intersect(System.Data.Objects.ObjectQuery{`0}) method was called.

The example in this topic is based on the AdventureWorks Sales Model. This example creates a new T:System.Data.Objects.ObjectQuery`1 object that contains the results of two other queries.

int productID1 = 900;
int productID2 = 950;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString = @"SELECT VALUE product 
        FROM AdventureWorksEntities.Products 
        AS product WHERE product.ProductID > @productID1";

    ObjectQuery<Product> productQuery =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    string queryString2 = @"SELECT VALUE product 
        FROM AdventureWorksEntities.Products 
        AS product WHERE product.ProductID > @productID2";

    ObjectQuery<Product> productQuery2 =
        new ObjectQuery<Product>(queryString2,
            context, MergeOption.NoTracking);

    ObjectQuery<Product> productQuery3 =
        productQuery.Intersect(productQuery2);

    productQuery3.Parameters.Add(new ObjectParameter("productID1", productID1));
    productQuery3.Parameters.Add(new ObjectParameter("productID2", productID2));

    Console.WriteLine("Result of Intersect");
    Console.WriteLine("------------------");

    // Iterate through the collection of Product items
    // after the Intersect method was called.
    foreach (Product result in productQuery3)
    {
        Console.WriteLine("Product Name: {0}", result.ProductID);
    }
}

.NET Framework
Disponibile da 3.5
Torna all'inizio
Mostra: