EntityCollection<TEntity>::Contains Method (TEntity)

 

Determines whether a specific object exists in the collection.

Namespace:   System.Data.Objects.DataClasses
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public:
virtual bool Contains(
	TEntity entity
) sealed

Parameters

entity
Type: TEntity

The object to locate in the EntityCollection<TEntity>.

Return Value

Type: System::Boolean

true if the object is found in the EntityCollection<TEntity>; otherwise, false.

Uses the T:System.Object.Equals method to compare the specified object with the objects already in the collection.

This example is based on the . To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define the Model and Mapping Files.

This example does the following:

  1. Creates two new SalesOrderHeader entities and adds them to the Contact entity.

  2. Gets all related ends from the RelationshipManager that is associated with the Contact entity.

  3. Iterates through the collection of IRelatedEnds.

  4. Gets the EntityCollection<TEntity> for each related end.

  5. Uses the Remove method to remove one of the entities from the collection.

  6. Calls the Contains method to determine whether the object was removed from the collection.

  7. Uses the Add method to add the entity back.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show: