DbSet<TEntity>.Add Method

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Adds the given entity to the context underlying the set in the Added state such that it will be inserted into the database when SaveChanges is called.

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
Public Overridable Function Add ( _
    entity As TEntity _
) As TEntity
'Usage
Dim instance As DbSet 
Dim entity As TEntity
Dim returnValue As TEntity

returnValue = instance.Add(entity)
public virtual TEntity Add(
    TEntity entity
)
public:
virtual TEntity Add(
    TEntity entity
)
abstract Add : 
        entity:'TEntity -> 'TEntity 
override Add : 
        entity:'TEntity -> 'TEntity 
public function Add(
    entity : TEntity
) : TEntity

Parameters

  • entity
    Type: TEntity
    The entity to add.

Return Value

Type: TEntity

Implements

IDbSet<TEntity>.Add(TEntity)

Remarks

Note that entities that are already in the context in some other state will have their state set to Added. Add is a no-op if the entity is already in the context in the Added state.

See Also

Reference

DbSet<TEntity> Class

System.Data.Entity Namespace