Skip to content

Move common DB operations in base repository #8

Description

@darkmakukudo

Just a suggestion to move all common operations in generic base repository.
Your thoughts on this.

public class BaseRepository<TEntity> : IDisposable, IBaseRepository<TEntity> where TEntity : class
    {
        protected readonly SqlConnection conn;

        public BaseRepository()
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();

            conn = new SqlConnection(config.GetConnectionString("DefaultConnection"));
        }

        public void Add(TEntity obj)
        {
            conn.Insert(obj);
        }

        public void Dispose()
        {
            conn.Dispose();
        }

        public TEntity FindById(int id)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<TEntity> GetAll()
        {
            //var selectQuery = "SELECT * FROM Test";
            var payloads = conn.GetAll<TEntity>().ToList();
            return payloads;
        }

        public void Remove(TEntity obj)
        {
            throw new NotImplementedException();
        }

        public void Update(TEntity obj)
        {
            throw new NotImplementedException();
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions