Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GenericRepository<T> : IGenericRepository<T> where T : class
- {
- public virtual T Add(T entity)
- {
- using (ApplicationDbContext _db = new ApplicationDbContext())
- {
- DbSet<T> _table = _db.Set<T>();
- using (var transaction = _db.Database.BeginTransaction())
- {
- try
- {
- var result = _table.Add(entity);
- transaction.Commit();
- return result;
- }
- catch
- {
- transaction.Rollback();
- return null;
- }
- }
- }
- }
- // and so on for other CRUD methods...
- }
- public class BuildingRespository : GenericRepository<Building>
- {
- public Building GetFullBuildingById(long Id)
- {
- using (ApplicationDbContext _db = new ApplicationDbContext())
- {
- return _db.Buildings.Include(x => x.BuildingClient).FirstOrDefault(x => x.Id == Id);
- }
- }
- // ...and so on for other entity class-specific requirements
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement