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.

LastBye
  • 1,143
  • 4
  • 19
  • 37
  • http://stackoverflow.com/questions/7431756/wrapping-dbsettentity-with-a-custom-dbset-idbset would help you – Ehsan Jun 24 '14 at 12:06
  • not the right one. looked at it before, I searched enough before making the post... – LastBye Jun 24 '14 at 12:24

0 Answers0