DLL layer interface design and dll layer interface design for Data Warehousing
1. Interface Design 2 1.1. IBaseRepository. cs 3 public interface IBaseRepository <T> 4 {5 T Add (T entity); 6 bool Update (T entity); 7 bool Delete (T entity ); 8 IQueryable <T> LoadEntities (Expression <Func <T, bool> wherelamties); 9 IQueryable <T> LoadPageEntities <S> (int pageSize, int pageIndex, out int total, expression <Func <T, bool> whereLambda, Expression <Func <T, S> orderbyLambda, bool isAsc); 10 11} 12 1.2. ICompanyRepository. cs 13 public interface ICompanyRepository: IBaseRepository <Company> 14 {15 16} 17 2. interface implementation 18 2.1 BaseRepository. cs 19 public class BaseRepository <T> where T: class, new () 20 {21 private ObjectContext dbContext 22 {23 get 24 {25 return EFDbContextFactory. getCurrentDbContext (); 26} 27} 28 public virtual T Add (T entity) 29 {30 dbContext. createObjectSet <T> (). addObject (entity); 31 return entity; 32} 33 34 public virtual bool Update (T entity) 35 {36 37 dbContext. objectStateManager. changeObjectState (entity, System. data. entityState. modified); 38 return true; 39} 40 41 public virtual bool Delete (T entity) 42 {43 dbContext. objectStateManager. changeObjectState (entity, System. data. entityState. deleted); 44 return true; 45} 46 47 public IQueryable <T> LoadEntities (Expression <Func <T, bool> wherelamties) 48 {49 return dbContext. createObjectSet <T> (). where (whereLambda ). asQueryable (); 50} 51 public IQueryable <T> LoadPageEntities <S> (int pageSize, int pageIndex, out int total, Expression <Func <T, bool> wherelamties, expression <Func <T, S> orderbyLambda, bool isAsc) 52 {53 total = dbContext. createObjectSet <T> (). where (whereLambda ). count (); 54 if (isAsc) 55 {56 return dbContext. createObjectSet <T> () 57. where (whereLambda) 58. orderBy (orderbyLambda) 59. skip (pageSize * (pageIndex-1) 60. asQueryable (); 61} 62 else 63 {64 return dbContext. createObjectSet <T> () 65. where (whereLambda) 66. orderByDescending (orderbyLambda) 67. skip (pageSize * (pageIndex-1) 68. asQueryable (); 69} 70} 71} 72 2.2 CompanyRepository. cs 73 public class CompanyRepository: BaseRepository <Company>, ICompanyRepository 74 {75 76} 77 III. IDbSession 78 3.1 IDbSession. cs 79 public interface IDbSession 80 {81 bytes MemberRepository {get;} 82 bytes ServiceTypeRepository {get;} 83 IServiceRepository ServiceRepository {get;} 84 ICompanyRepository CompanyRepository {get ;} 85 IProductGroupRepository ProductGroupRepository {get;} 86 int SaveChanges (); 87} 88 3.2 DbSession. cs 89 public class DbSession: IDbSession 90 {91 private member _ MemberRepository; 92 private member _ ServiceTypeRepository; 93 private member _ ServiceRepository; 94 private member _ CompanyRepository; 95 private member _ ProductGroupRepository; 96 97 public IMemberRepository MemberRepository 98 {99 get100 {101 if (_ MemberRepository = null) 102 {103 _ MemberRepository = new MemberRepository (); 104} 105 return _ MemberRepository; 106} 107} 108 109 public topology {111 get112 {113 if (_ ServiceTypeRepository = null) 114 {115 _ ServiceTypeRepository = new ServiceTypeRepository (); 116} 117 return _ ServiceTypeRepository; 118} 119} 120 121 public IServiceRepository ServiceRepository122 {123 get124 {125 if (_ ServiceRepository = null) 126 {127 _ ServiceRepository = new ServiceRepository (); 128} 129 return _ ServiceRepository; 130} 131} 132 133 public ICompanyRepository detail {135 get136 {137 if (_ CompanyRepository = null) 138 {139 _ CompanyRepository = new CompanyRepository (); 140} 141 return _ CompanyRepository; 142} 143} 144 145 public topology {147 get148 {149 if (_ ProductGroupRepository = null) 150 {151 _ ProductGroupRepository = new ProductGroupRepository (); 152} 153 return _ ProductGroupRepository; 154} 155} 156 157 public int SaveChanges () 158 {159 return EFDbContextFactory. getCurrentDbContext (). saveChanges (); 160} 161 162 163 164} 165 EFDbContextFactory. cs166 public class EFDbContextFactory167 {168 public static ObjectContext GetCurrentDbContext () 169 {170 171 172 // The only ObjectContext dbContext = (ObjectContext) CallContext in the thread. getData ("dbContext"); 173 if (dbContext = null) 174 {175 dbContext = new SimpleNewsContext (); 176 CallContext. setData ("dbContext", dbContext); 177} 178 return dbContext; 179} 180 181}