DbSet<TEntity> クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
DbSet<TEntity>を使用して、TEntityのインスタンスのクエリと保存を行うことができます。
DbSet<TEntity>に対する LINQ クエリは、データベースに対するクエリに変換されます。
public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, Microsoft.EntityFrameworkCore.Query.Internal.IAsyncEnumerableAccessor<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.Linq.IQueryable<TEntity> where TEntity : class
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, System.Collections.Generic.IEnumerable<TEntity>, System.ComponentModel.IListSource, System.Linq.IQueryable<TEntity> where TEntity : class
public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, Microsoft.EntityFrameworkCore.Query.Internal.IAsyncEnumerableAccessor<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.ComponentModel.IListSource, System.Linq.IQueryable<TEntity> where TEntity : class
public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, System.Collections.Generic.IAsyncEnumerable<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.ComponentModel.IListSource, System.Linq.IQueryable<TEntity> where TEntity : class
public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, System.Collections.Generic.IEnumerable<TEntity>, System.ComponentModel.IListSource, System.Linq.IQueryable<TEntity> where TEntity : class
type DbSet<'Entity (requires 'Entity : null)> = class
interface IQueryable<'Entity (requires 'Entity : null)>
interface seq<'Entity (requires 'Entity : null)>
interface IEnumerable
interface IQueryable
interface IAsyncEnumerableAccessor<'Entity (requires 'Entity : null)>
interface IInfrastructure<IServiceProvider>
[<System.Runtime.CompilerServices.Nullable(0)>]
type DbSet<'Entity (requires 'Entity : null)> = class
interface IQueryable<'Entity (requires 'Entity : null)>
interface seq<'Entity (requires 'Entity : null)>
interface IEnumerable
interface IQueryable
interface IInfrastructure<IServiceProvider>
interface IListSource
type DbSet<'Entity (requires 'Entity : null)> = class
interface IQueryable<'Entity (requires 'Entity : null)>
interface seq<'Entity (requires 'Entity : null)>
interface IEnumerable
interface IQueryable
interface IAsyncEnumerableAccessor<'Entity (requires 'Entity : null)>
interface IInfrastructure<IServiceProvider>
interface IListSource
type DbSet<'Entity (requires 'Entity : null)> = class
interface IQueryable<'Entity (requires 'Entity : null)>
interface seq<'Entity (requires 'Entity : null)>
interface IEnumerable
interface IQueryable
interface IAsyncEnumerable<'Entity (requires 'Entity : null)>
interface IInfrastructure<IServiceProvider>
interface IListSource
type DbSet<'Entity (requires 'Entity : null)> = class
interface IQueryable<'Entity (requires 'Entity : null)>
interface seq<'Entity (requires 'Entity : null)>
interface IEnumerable
interface IQueryable
interface IInfrastructure<IServiceProvider>
interface IListSource
Public MustInherit Class DbSet(Of TEntity)
Implements IAsyncEnumerableAccessor(Of TEntity), IEnumerable(Of TEntity), IInfrastructure(Of IServiceProvider), IQueryable(Of TEntity)
Public MustInherit Class DbSet(Of TEntity)
Implements IEnumerable(Of TEntity), IInfrastructure(Of IServiceProvider), IListSource, IQueryable(Of TEntity)
Public MustInherit Class DbSet(Of TEntity)
Implements IAsyncEnumerableAccessor(Of TEntity), IEnumerable(Of TEntity), IInfrastructure(Of IServiceProvider), IListSource, IQueryable(Of TEntity)
Public MustInherit Class DbSet(Of TEntity)
Implements IAsyncEnumerable(Of TEntity), IEnumerable(Of TEntity), IInfrastructure(Of IServiceProvider), IListSource, IQueryable(Of TEntity)
型パラメーター
- TEntity
このセットによって操作されるエンティティの種類。
- 継承
-
DbSet<TEntity>
- 派生
- 属性
- 実装
-
IInfrastructure<IServiceProvider> Microsoft.EntityFrameworkCore.Query.Internal.IAsyncEnumerableAccessor<TEntity> IEnumerable<T> IEnumerable<TEntity> IEnumerable IQueryable IQueryable<TEntity> IListSource IAsyncEnumerable<TEntity>
注釈
DbSet<TEntity>に対する LINQ クエリの結果には、データベースから返された結果が含まれます。また、データベースに永続化されていないコンテキストで行われた変更は反映されない場合があります。 たとえば、結果には新しく追加されたエンティティは含まれませんが、削除対象としてマークされたエンティティが含まれている可能性があります。
使用されているデータベースによっては、 DbSet<TEntity> に対する LINQ クエリの一部が、データベース クエリに変換されるのではなく、メモリ内で評価される場合があります。
DbSet<TEntity>オブジェクトは通常、派生DbContextのDbSet<TEntity> プロパティまたは Set<TEntity>() メソッドから取得されます。
Entity Framework Core では、同じ DbContext インスタンス上での複数の並列操作の実行がサポートされていません。 これには、非同期クエリの並列実行と、複数のスレッドからの明示的な同時使用の両方が含まれます。 したがって、常に非同期呼び出しをすぐに待機するか、並列で実行される操作に個別の DbContext インスタンスを使用します。 詳細と例については、 DbContext スレッドの問題の回避に 関するページを参照してください。
詳細と例については、「 DbContext の有効期間、構成、初期化」、 EF Core を使用したデータの照会、および 変更の追跡 を参照してください。
コンストラクター
| Name | 説明 |
|---|---|
| DbSet<TEntity>() |
DbSet<TEntity>を使用して、 |
プロパティ
| Name | 説明 |
|---|---|
| EntityType |
このセットに関連付けられている IEntityType メタデータ。 |
| Local |
このセット内のすべての Added、Unchanged、Modified エンティティのローカル ビューを表す LocalView<TEntity> を取得します。 |
メソッド
| Name | 説明 |
|---|---|
| Add(TEntity) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AddAsync(TEntity, CancellationToken) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AddRange(IEnumerable<TEntity>) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AddRange(TEntity[]) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AddRangeAsync(IEnumerable<TEntity>, CancellationToken) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AddRangeAsync(TEntity[]) |
SaveChanges()が呼び出されたときにデータベースに挿入されるように、Added状態で、指定されたエンティティと、まだ追跡されていない他の到達可能なエンティティの追跡を開始します。 |
| AsAsyncEnumerable() |
IAsyncEnumerable<T>として型指定されたこのオブジェクトを返します。 |
| AsQueryable() |
IQueryable<T>として型指定されたこのオブジェクトを返します。 |
| Attach(TEntity) |
既定では、 Unchanged 状態を使用して、指定されたエンティティと特定のエンティティから到達可能なエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
| AttachRange(IEnumerable<TEntity>) |
既定では、 Unchanged 状態を使用して、特定のエンティティから到達可能な特定のエンティティとエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
| AttachRange(TEntity[]) |
既定では、 Unchanged 状態を使用して、特定のエンティティから到達可能な特定のエンティティとエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
| Entry(TEntity) |
指定したエンティティの EntityEntry<TEntity> を取得します。 エントリは、エンティティの変更追跡情報と操作へのアクセスを提供します。 |
| Find(Object[]) |
指定された主キー値を持つエンティティを検索します。 指定された主キー値を持つエンティティがコンテキストによって追跡されている場合は、データベースに要求を行わずに直ちに返されます。 それ以外の場合は、指定された主キー値を持つエンティティのクエリがデータベースに対して実行され、このエンティティが見つかった場合はコンテキストにアタッチされて返されます。 エンティティが見つからない場合は、null が返されます。 |
| FindAsync(Object[], CancellationToken) |
指定された主キー値を持つエンティティを検索します。 指定された主キー値を持つエンティティがコンテキストによって追跡されている場合は、データベースに要求を行わずに直ちに返されます。 それ以外の場合は、指定された主キー値を持つエンティティのクエリがデータベースに対して実行され、このエンティティが見つかった場合はコンテキストにアタッチされて返されます。 エンティティが見つからない場合は、null が返されます。 |
| FindAsync(Object[]) |
指定された主キー値を持つエンティティを検索します。 指定された主キー値を持つエンティティがコンテキストによって追跡されている場合は、データベースに要求を行わずに直ちに返されます。 それ以外の場合は、指定された主キー値を持つエンティティのクエリがデータベースに対して実行され、このエンティティが見つかった場合はコンテキストにアタッチされて返されます。 エンティティが見つからない場合は、null が返されます。 |
| GetAsyncEnumerator(CancellationToken) |
列挙時にデータベースに対して非同期的にクエリを実行する IAsyncEnumerator<T> を返します。 |
| Remove(TEntity) |
SaveChanges()が呼び出されたときにデータベースから削除されるように、Deleted状態の指定されたエンティティの追跡を開始します。 |
| RemoveRange(IEnumerable<TEntity>) |
SaveChanges()が呼び出されたときにデータベースから削除されるように、Deleted状態の特定のエンティティの追跡を開始します。 |
| RemoveRange(TEntity[]) |
SaveChanges()が呼び出されたときにデータベースから削除されるように、Deleted状態の特定のエンティティの追跡を開始します。 |
| Update(TEntity) |
既定では、 Modified 状態を使用して、指定されたエンティティと特定のエンティティから到達可能なエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
| UpdateRange(IEnumerable<TEntity>) |
既定では、 Modified 状態を使用して、特定のエンティティから到達可能な特定のエンティティとエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
| UpdateRange(TEntity[]) |
既定では、 Modified 状態を使用して、特定のエンティティから到達可能な特定のエンティティとエントリの追跡を開始しますが、別の状態が使用される場合は以下を参照してください。 |
明示的なインターフェイスの実装
| Name | 説明 |
|---|---|
| IAsyncEnumerable<TEntity>.GetAsyncEnumerator(CancellationToken) |
列挙時にデータベースに対して非同期的にクエリを実行する IAsyncEnumerator<T> を返します。 |
| IAsyncEnumerableAccessor<TEntity>.AsyncEnumerable |
列挙時にデータベースに対してクエリを非同期的に実行する IAsyncEnumerable<T> を返します。 |
| IEnumerable.GetEnumerator() |
列挙時にデータベースに対してクエリを実行し、データベースからすべてのエンティティを読み込む IEnumerator を返します。 |
| IEnumerable<TEntity>.GetEnumerator() |
列挙時にデータベースに対してクエリを実行し、データベースからすべてのエンティティを読み込む IEnumerator<T> を返します。 |
| IInfrastructure<IServiceProvider>.Instance |
サービスの解決に使用されているスコープ付き IServiceProvider を取得します。 |
| IListSource.ContainsListCollection |
コレクションが System.Collections.IList オブジェクトのコレクションであるかどうかを示す値を取得します。
常に |
| IListSource.GetList() |
このメソッドは、データ を DbSet<TEntity>に直接バインドしようとするときに、データ バインディング フレームワークによって呼び出されます。 |
| IQueryable.ElementType |
IQueryable 要素型を取得します。 |
| IQueryable.Expression |
IQueryable LINQ 式を取得します。 |
| IQueryable.Provider |
IQueryable プロバイダーを取得します。 |