Guest User

Untitled

a guest
Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public class Entity
  2. {
  3.  
  4. public int PrimaryKey;
  5.  
  6. }
  7. public class Repository
  8. {
  9. protected DbConnection Context;
  10.  
  11. protected Repository(DbConnection context)
  12. {
  13. Context = context;
  14. }
  15. }
  16.  
  17. interface IRepository<TEntity> where TEntity : Entity
  18. {
  19. void Insert(TEntity entity);
  20. void Update(TEntity entity);
  21. void Delete(TEntity entity);
  22. }
  23.  
  24. public class BookRepository : Repository, IRepository<Book>
  25. {
  26. public BookRepository(DbConnection context) : base(context){}
  27.  
  28. public void Insert(Book entity) { }
  29.  
  30. public void Update(Book entity) { }
  31.  
  32. public void Delete(Book entity) { }
  33. }
  34. public class Book : Entity
  35. {
  36.  
  37. public Book() { }
  38. }
  39.  
  40. public class BookMarketRepositoy : Repository, IRepository<BookMarket>
  41. {
  42. public BookMarketRepositoy(DbConnection context) : base(context){}
  43.  
  44. public void Insert(BookMarket entity) { }
  45.  
  46.  
  47. public void Update(BookMarket entity) { }
  48.  
  49.  
  50. public void Delete(BookMarket entity) { }
  51.  
  52. }
  53. public class BookMarket : Entity
  54. {
  55. public BookMarket() { }
  56. }
  57.  
  58. public class DbContext
  59. {
  60. private DbConnection _conn;
  61. public BookMarketRepositoy BookMarkets { get; private set; }
  62. public BookRepository Books { get; private set; }
  63.  
  64. public DbContext(DbConnection conn)
  65. {
  66. _conn = conn;
  67. if (_conn.State != ConnectionState.Open)
  68. {
  69. _conn.Open();
  70. }
  71. BookMarkets = new BookMarketRepositoy(conn);
  72. Books = new BookRepository(conn);
  73. }
  74. }
Add Comment
Please, Sign In to add comment