Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I'm trying to write an interface to define the set of operations I expect my repositories' Unit of Work implementations to have, and I want this interface to be fulfilled by EF Core's DbContext cla...
#1: Initial revision
Declaring interface members with generic return types: "The type parameter [generic type] cannot be used with type arguments"
I'm trying to write an interface to define the set of operations I expect my repositories' Unit of Work implementations to have, and I want this interface to be fulfilled by EF Core's `DbContext` class. So far this is what I got: _(I know the name is awful, suggestions accepted)_: ```cs public interface IDbContextable<TContext, TEntityEntry> where TContext : class, IDisposable where TEntityEntry : class { public TEntityEntry Add([NotNullAttribute] object entity); public TEntityEntry<TEntity> Add<TEntity>([NotNullAttribute] TEntity entity) where TEntity : class; public int SaveChanges(); } ``` The first `Add` method's signature from EF Core is: `public virtual EntityEntry Add([NotNullAttribute] object entity);` - and it works fine. I'm having trouble with the second. The compiler complains: > Error CS0307 The type parameter 'TEntityEntry' cannot be used with type arguments For completeness, my context class looks like this: ```cs public partial class EntityFrameworkContext : DbContext, IDbContextable<EntityFrameworkContext, EntityEntry> { //... some extra methods here } ``` How to properly declare the interface to get rid of the error, and so that the signature: `public virtual EntityEntry<TEntity> Add<TEntity>([NotNullAttribute] TEntity entity) where TEntity : class;` from EF Core becomes valid? Thanks.