|
64 | 64 |
|
65 | 65 |
|
66 | 66 | ## Examples
|
67 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 67 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
68 | 68 |
|
69 | 69 | This example does the following:
|
70 | 70 |
|
|
150 | 150 | <format type="text/markdown"><. |
| 153 | + The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method adds an object to an <xref:System.Data.Objects.DataClasses.EntityCollection%601> and creates a relationship between the two objects. When the source object is attached to an <xref:System.Data.Objects.ObjectContext> instance, the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method also adds the object to the <xref:System.Data.Objects.ObjectContext>. This operation is translated into an insert operation in the data source when <xref:System.Data.Objects.ObjectContext.SaveChanges%2A> is called. For more information, see [Creating, Adding, Modifying, and Deleting Objects](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738695(v=vs.100)). |
154 | 154 |
|
155 | 155 | The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method can be called multiple times on the same object instance.
|
156 | 156 |
|
157 | 157 |
|
158 | 158 |
|
159 | 159 | ## Examples
|
160 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 160 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
161 | 161 |
|
162 | 162 | This example creates two new `SalesOrderHeader` entities, adds them to the `Contact` entity, and, after removing an object, uses the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method to add the object back to the collection.
|
163 | 163 |
|
|
206 | 206 | <format type="text/markdown"><. |
| 209 | + The <xref:System.Data.Objects.ObjectContext.Attach%2A> method is used to define relationships between an object and a collection of related objects when both the source object and the collection of related objects already exist in the object context. To attach an object or an object graph where the relationships are already defined, call the <xref:System.Data.Objects.ObjectContext.Attach%2A> method on the <xref:System.Data.Objects.ObjectContext>. To create a new object that is related to the source object, call the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method on the <xref:System.Data.Objects.DataClasses.EntityCollection%601>. For more information, see [Attaching and Detaching Objects](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738470(v=vs.100)). |
210 | 210 |
|
211 | 211 | If the collection is already filled or partially filled, the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Attach%2A> method merges existing entities with the given entities. The given entities are not assumed to be the complete set of related entities.
|
212 | 212 |
|
|
249 | 249 | <format type="text/markdown"><. |
| 252 | + The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Attach%2A> method is used to define relationships between two objects when both objects already exist in the object context. To attach an object or an object graph where the relationships are already defined, call the <xref:System.Data.Objects.ObjectContext.Attach%2A> method on the <xref:System.Data.Objects.ObjectContext>. To create a new object that is related to the source object, call the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Add%2A> method on the <xref:System.Data.Objects.DataClasses.EntityCollection%601>. For more information, see [Attaching and Detaching Objects](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738470(v=vs.100)). |
253 | 253 |
|
254 | 254 | If the <xref:System.Data.Objects.DataClasses.EntityCollection%601> already has loaded objects, the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Attach%2A> method merges the object together with the existing objects in the <xref:System.Data.Objects.DataClasses.EntityCollection%601>.
|
255 | 255 |
|
|
262 | 262 |
|
263 | 263 |
|
264 | 264 | ## Examples
|
265 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 265 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
266 | 266 |
|
267 | 267 | This example attaches a collection of detached `SalesOrderDetail` objects and a detached `SalesOrderHeader` object to an object context, and then defines the relationships between the `SalesOrderHeader` object and each `SalesOrderDetail` object.
|
268 | 268 |
|
|
355 | 355 |
|
356 | 356 |
|
357 | 357 | ## Examples
|
358 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 358 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
359 | 359 |
|
360 | 360 | This example does the following:
|
361 | 361 |
|
|
477 | 477 | ## Examples
|
478 | 478 | This example is based on a modified version of the . This version supports table-per-type inheritance with `Course` as an abstract type. Complete the walkthrough to modify the School model to support the table-per-type inheritance example used in this topic.
|
479 | 479 |
|
480 |
| - This example shows how to use <xref:System.Data.Objects.DataClasses.EntityCollection%601.CreateSourceQuery%2A> to filter objects in an <xref:System.Data.Objects.DataClasses.EntityCollection%601> and bind only to objects of a specific type. For a complete version of this example, see [How to: Bind Controls to Derived Types](https://msdn.microsoft.com/library/09730c14-3b7b-4563-af4a-7ecfa4e34bd5). |
| 480 | + This example shows how to use <xref:System.Data.Objects.DataClasses.EntityCollection%601.CreateSourceQuery%2A> to filter objects in an <xref:System.Data.Objects.DataClasses.EntityCollection%601> and bind only to objects of a specific type. For a complete version of this example, see [How to: Bind Controls to Derived Types](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/dd283135(v=vs.100)). |
481 | 481 |
|
482 | 482 |
|
483 | 483 |
|
@@ -590,7 +590,7 @@ This method calls the internal `RelatedEnd.ValidateLoad` method before loading t
|
590 | 590 |
|
591 | 591 |
|
592 | 592 | ## Examples
|
593 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 593 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
594 | 594 |
|
595 | 595 | This example loads the related `SalesOrderHeader` objects for the `Contact` entity.
|
596 | 596 |
|
@@ -702,14 +702,14 @@ This method calls the internal `RelatedEnd.ValidateLoad` method before loading t
|
702 | 702 | <format type="text/markdown"><. |
| 705 | + The <xref:System.Data.Objects.DataClasses.EntityCollection%601.Remove%2A> method also deletes the relationship between the source object and the object being removed from the collection. If the relationship has a referential integrity constraint, calling the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Remove%2A> method on a dependent object marks both the relationship and the dependent object for deletion. This occurs because the constraint indicates that the dependent object cannot exist without a relationship to the parent. For more information, see [ReferentialConstraint Element (CSDL)](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738464(v=vs.100)). |
706 | 706 |
|
707 | 707 | <xref:System.Data.Objects.DataClasses.EntityCollection%601.Remove%2A> returns `false` when the specified object is not in the collection.
|
708 | 708 |
|
709 | 709 |
|
710 | 710 |
|
711 | 711 | ## Examples
|
712 |
| - 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](https://msdn.microsoft.com/library/73f6ae1d-b3b2-4577-aebd-ad5a75954e9e) and [How to: Manually Define the Model and Mapping Files](https://msdn.microsoft.com/library/d4fd6864-f2a1-48f0-aa32-1e318775a99a). |
| 712 | + 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](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb738546(v=vs.100)) and [How to: Manually Define the Model and Mapping Files](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/bb399785(v=vs.100)). |
713 | 713 |
|
714 | 714 | This example uses the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Remove%2A> method to remove one of the entities from the collection and then calls the <xref:System.Data.Objects.DataClasses.EntityCollection%601.Contains%2A> method to determine whether the object was removed from the collection.
|
715 | 715 |
|
|
0 commit comments