DataServiceContext.AddObject Method (String, Object)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Adds the specified object to the set of objects that the DataServiceContext is tracking.

Namespace:   System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public void AddObject(
	string entitySetName,
	object entity


Type: System.String

The name of the entity set to which the resource will be added.

Type: System.Object

The object to be tracked by the DataServiceContext.

Exception Condition

When entitySetName or entity is null.


When entitySetName is empty.


When entity does not have a key property defined.


When the entity is already being tracked by the context.

The object is put into the tracking set of the DataServiceContext in the Added state. The DataServiceContext will try to insert the object by HTTP POST on the next call to SaveChanges. This method does not add objects related to the specified entity to the DataServiceContext. Each object must be added through a separate call to AddObject.

The method does not validate that the entity set specified is in the data service associated with the DataServiceContext or that the added object has the required properties needed to be added to the specified entity set.

.NET Framework
Available since 3.5
Available since 2.0
Return to top