question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BaseRepository does not work with generic TDbConnection.

See original GitHub issue

I’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.

Screenshot 2023-04-10 123221

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:closed
  • Created 5 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
plsftcommented, Apr 13, 2023

@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!

1reaction
plsftcommented, Apr 12, 2023

Direct Use: image

DI Use:

image

image

DI via Business Logic Service

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found