Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Entity
- {
- public int PrimaryKey;
- }
- public class Repository
- {
- protected DbConnection Context;
- protected Repository(DbConnection context)
- {
- Context = context;
- }
- }
- interface IRepository<TEntity> where TEntity : Entity
- {
- void Insert(TEntity entity);
- void Update(TEntity entity);
- void Delete(TEntity entity);
- }
- public class BookRepository : Repository, IRepository<Book>
- {
- public BookRepository(DbConnection context) : base(context){}
- public void Insert(Book entity) { }
- public void Update(Book entity) { }
- public void Delete(Book entity) { }
- }
- public class Book : Entity
- {
- public Book() { }
- }
- public class BookMarketRepositoy : Repository, IRepository<BookMarket>
- {
- public BookMarketRepositoy(DbConnection context) : base(context){}
- public void Insert(BookMarket entity) { }
- public void Update(BookMarket entity) { }
- public void Delete(BookMarket entity) { }
- }
- public class BookMarket : Entity
- {
- public BookMarket() { }
- }
- public class DbContext
- {
- private DbConnection _conn;
- public BookMarketRepositoy BookMarkets { get; private set; }
- public BookRepository Books { get; private set; }
- public DbContext(DbConnection conn)
- {
- _conn = conn;
- if (_conn.State != ConnectionState.Open)
- {
- _conn.Open();
- }
- BookMarkets = new BookMarketRepositoy(conn);
- Books = new BookRepository(conn);
- }
- }
Add Comment
Please, Sign In to add comment