BaseRepository does not work with generic TDbConnection.
See original GitHub issueI’m trying to add RDB to my app but I can’t get it to compile. The BaseRepository (from the UnitOfWork / GenericRepository docs) will not accept a DbConnection of type TDbConnection, rather it seems to require SqlConnection.
public class EntityRepository<TEntity, TDbConnection> : BaseRepository<TEntity, TDbConnection>, IRepository<TEntity, TDbConnection>
where TEntity : class
where TDbConnection : IDbConnection
{
private IUnitOfWork<DbConnection> _unitOfWork;
public EntityRepository(IOptions<AppSettings> options)
: base(options.Value.ConnectionString) { }
public void Attach(IUnitOfWork<DbConnection> unitOfWork) =>
_unitOfWork = unitOfWork;
public TResult Save<TResult>(TEntity entity) =>
Insert<TResult>(entity,
transaction: _unitOfWork.Transaction);
public int SaveAll(IEnumerable<TEntity> entities) =>
InsertAll(entities,
transaction: _unitOfWork.Transaction);
public int Delete(object id) =>
Delete(id,
transaction: _unitOfWork.Transaction);
public TResult Merge<TResult>(TEntity entity) =>
Merge<TResult>(entity,
transaction: _unitOfWork?.Transaction);
public TEntity Query(object id) =>
Query(id,
transaction: _unitOfWork?.Transaction)?.FirstOrDefault();
public int Update(TEntity entity) =>
Update(entity,
transaction: _unitOfWork?.Transaction);
}
Issue Analytics
- State:
- Created 5 months ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
c# - Problems with Generic Repository Pattern and Entity ...
Below is the BaseRespository.cs code that is use that I use as Generic class for entity framework. I inherit this class as parent...
Read more >Generic repository pattern with db-first and AutoMapper
My app requires db-first approach. I would like to return list of all users using generic method ListAllAsync() from BaseRepository . I have ......
Read more >BaseRepository.cs
A hybrid ORM library for .NET. Contribute to mikependon/RepoDB development by creating an account on GitHub.
Read more >Unit of Work
Ensure that this interface is accepting a generic type of the connection object. Then, save the following properties that will hold the state...
Read more >Generic Repositories with different IDbConnections
The problem is that i make a generic repository because data of first table of first database are some properties the same and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mikependon thanks for the reference project! I’ll review and see how I can use it. really impressed with RDB so far. I’ve used PetaPoco and NPoco for years, Massive/MightOrm too, because I felt EntityFx was too bloated with too much ceremony. The performance of RDB and the bulk import and merge features are killer. great work!
Direct Use:
DI Use:
DI via Business Logic Service