Share via


Metodo DbContext.Set<TEntity>

[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<TEntity> 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(Of TEntity As Class) As DbSet(Of TEntity)
'Utilizzo
Dim instance As DbContext 
Dim returnValue As DbSet(Of TEntity)

returnValue = instance.Set()
[SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")]
public virtual DbSet<TEntity> Set<TEntity>()
where TEntity : class
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1716:IdentifiersShouldNotMatchKeywords", MessageId = L"Set")]
public:
generic<typename TEntity>
where TEntity : ref class 
virtual DbSet<TEntity>^ Set()
[<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")>]
abstract Set : unit -> DbSet<'TEntity>  when 'TEntity : not struct
[<SuppressMessageAttribute("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set")>]
override Set : unit -> DbSet<'TEntity>  when 'TEntity : not struct
JScript does not support generic types and methods.

Parametri di tipo

  • TEntity
    Tipo di entità per cui deve essere restituito un set.

Valore restituito

Tipo: System.Data.Entity.DbSet<TEntity>
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 non 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<TEntity>.

Vedere anche

Riferimento

DbContext Classe

Overload Set

Spazio dei nomi System.Data.Entity