Share via


Metodo DbContext.Set (Type)

[Questa pagina è specifica della versione 6 di Entity Framework. La versione più recente è disponibile come pacchetto NuGet per "Entity Framework". Per ulteriori informazioni su Entity Framework, vedere la pagina msdn.com/data/ef.]

Restituisce un'istanza di DbSet non generica per l'accesso alle entità del tipo specificato nel contesto e all'archivio sottostante.

Spazio dei nomi:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Sintassi

'Dichiarazione
<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId := "Set")> _
Public Overridable Function Set ( _
    entityType As Type _
) As DbSet
'Utilizzo
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

Parametri

  • entityType
    Tipo: System.Type
    Tipo di entità per cui deve essere restituito un set.

Valore restituito

Tipo: System.Data.Entity.DbSet
Set per il tipo di entità specificato.

Note

In Entity Framework è necessario che questo metodo restituisca la stessa istanza ogni volta che viene chiamato per un tipo di entità o un'istanza del contesto specifica. L'oggetto DbSet<TEntity> generico restituito dal metodo Set(Type) deve inoltre eseguire il wrapping della stessa query e dello stesso set di entità sottostanti. È necessario mantenere queste invarianti se si esegue l'override del metodo con un'operazione che non sia la creazione di copie di test per gli unit test. Per ulteriori dettagli, vedere la classe DbSet.

Vedere anche

Riferimento

DbContext Classe

Overload Set

Spazio dei nomi System.Data.Entity