DataServiceContext.AddObject Method

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

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

Syntax

'Declaration
Public Sub AddObject ( _
    entitySetName As String, _
    entity As Object _
)
'Usage
Dim instance As DataServiceContext 
Dim entitySetName As String 
Dim entity As Object

instance.AddObject(entitySetName, entity)
public void AddObject(
    string entitySetName,
    Object entity
)
public:
void AddObject(
    String^ entitySetName, 
    Object^ entity
)
member AddObject : 
        entitySetName:string * 
        entity:Object -> unit
public function AddObject(
    entitySetName : String, 
    entity : Object
)

Parameters

  • entitySetName
    Type: System.String
    The name of the entity set to which the resource will be added.

Exceptions

Exception Condition
ArgumentNullException

When entitySetName or entity is null.

ArgumentException

When entitySetName is empty.

-or-

When entity does not have a key property defined.

InvalidOperationException

When the entity is already being tracked by the context.

Remarks

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.

See Also

Reference

DataServiceContext Class

System.Data.Services.Client Namespace