How to create a custom DbSet

How to create a custom DbSet that will be used in our context,

here I received from DbSet which is given below.

In context, I:

public CustomDbSet<Items> MyDbSet { get; set; }

when we reach " context.MyDbSet" it is null , Changing this to a simple DbSet, it will work and correctly initialized,

public class CustomDbSet<TEntity> : DbSet<TEntity>, IDbSet<TEntity> where TEntity : Entity, new()
{
    #region Private Fields
    private readonly ObservableCollection<TEntity> _items;
    private readonly IQueryable _query;
    #endregion Private Fields

    public CustomDbSet()
        //: base()
        //: base((IInternalQuery<TEntity>)internalSet)
    {
        _items = new ObservableCollection<TEntity>();
        _query = _items.AsQueryable();
    }
}

It will have more properties.

+4
source share

Source: https://habr.com/ru/post/1545826/


All Articles