9

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

here I ferived from DbSet which the code sample is provided below.

In the Context I have:

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

any time we reach "context.MyDbSet" it's null, Changing this to a simple DbSet it will work and it's properly 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();
    }
}

There will be more properties in it.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.