Share via


DbContext.Set Method (Type)

[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.]

Returns a non-generic DbSet instance for access to entities of the given type in the context and the underlying store.

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

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId := "Set")> _
Public Overridable Function Set ( _
    entityType As Type _
) As DbSet
'Usage
Dim instance As DbContext 
Dim entityType As Type 
Dim returnValue As DbSet 

returnValue = instance.Set(entityType)
[SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")]
public virtual DbSet Set(
    Type entityType
)
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1716:IdentifiersShouldNotMatchKeywords", MessageId = L"Set")]
public:
virtual DbSet^ Set(
    Type^ entityType
)
[<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")>]
abstract Set : 
        entityType:Type -> DbSet 
[<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")>]
override Set : 
        entityType:Type -> DbSet
public function Set(
    entityType : Type
) : DbSet

Parameters

  • entityType
    Type: System.Type
    The type of entity for which a set should be returned.

Return Value

Type: System.Data.Entity.DbSet
A set for the given entity type.

Remarks

Note that Entity Framework requires that this method return the same instance each time that it is called for a given context instance and entity type. Also, the generic DbSet<TEntity> returned by the Set(Type) method must wrap the same underlying query and set of entities. These invariants must be maintained if this method is overridden for anything other than creating test doubles for unit testing. See the DbSet class for more details.

See Also

Reference

DbContext Class

Set Overload

System.Data.Entity Namespace