EntityList<TEntity>.InsertOnSubmit Method

Marks the specified entity for insertion into the list on the next call of SubmitChanges().

Namespace:  Microsoft.SharePoint.Linq
Assembly:  Microsoft.SharePoint.Linq (in Microsoft.SharePoint.Linq.dll)

Syntax

'Declaration
Public Sub InsertOnSubmit ( _
    entity As TEntity _
)
'Usage
Dim instance As EntityList
Dim entity As TEntity

instance.InsertOnSubmit(entity)
public void InsertOnSubmit(
    TEntity entity
)

Parameters

  • entity
    Type: TEntity

    The entity to be marked for insertion.

Exceptions

Exception Condition
ArgumentNullException

entity is a null reference (Nothing in Visual Basic).

InvalidOperationException

Object tracking is not enabled for the DataContext object.

- or -

entity is not of the same type as the list items.

- or -

entity has been deleted.

- or -

entity has been updated.

- or -

There is a problem with the internal ID of entity that is used by the object tracking system.

Remarks

entity is usually a list item, but it can be a detached entity of the same type as the list items.

Examples

The following is an example of InsertOnSubmit(TEntity) in use:

// Create the new list item.
TeamMember bob = new TeamMember() { Title=”Bob Smith” };

// Set the item to be inserted.
teamSite.TeamMembers.InsertOnSubmit(bob);

// Write changes to the content database.
teamSite.SubmitChanges();

// Try-catch blocks omitted for readability.
' Create the new list item.
Dim bob As New TeamMember() With {.Title="Bob Smith"}

' Set the item to be inserted.
teamSite.TeamMembers. InsertOnSubmit(bob)

' Write changes to the content database.
teamSite.SubmitChanges()

' Try-catch blocks omitted for readability.

See Also

Reference

EntityList<TEntity> Class

EntityList<TEntity> Members

Microsoft.SharePoint.Linq Namespace

Other Resources

How to: Write to Lists Using LINQ to SharePoint