0

is that possible create an abstract class from DbQuery and IDbSet? I'm trying to create an abstraction layer for my unit testing.

public abstract class BaseDbSet<T> : DbQuery<T>, IDbSet<T> where T : Entity
{
    #region IDbSet<T> Members

    public abstract T Add(T entity);
    public abstract T Attach(T entity);
    public abstract TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, T;
    public abstract T Create();
    public abstract T Find(params object[] keyValues);
    public abstract ObservableCollection<T> Local { get; }
    public abstract T Remove(T entity);

    #endregion
}

I'm getting the following error:

Error 1 The type 'System.Data.Entity.Infrastructure.DbQuery' has no constructors defined @path\BaseDbSet.cs

If I try to add a constructor I get:

Error 1 The type 'System.Data.Entity.Infrastructure.DbQuery' has no constructors defined @path\BaseDbSet.cs

Vinicius Rocha
  • 4,023
  • 4
  • 29
  • 38

1 Answers1

2

That is because the constructors are declared as internal. Hence you can not access them.

Unit testing EF code is a flawed concept. Check this answer. You are wasting valuable time on unnecessary abstractions.

Community
  • 1
  • 1
Eranga
  • 32,181
  • 5
  • 97
  • 96