SHARE
TWEET

Untitled

a guest Jan 12th, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class TestController : ApiController
  2. {
  3.     [HttpGet]
  4.     public IEnumerable<Test> GetTests()
  5.     {
  6.         using(var context = new DatabaseContext())
  7.         {
  8.             return context.Tests.Where(w=>w.Enabled).ToList();
  9.         }
  10.     }
  11. }
  12.    
  13. try
  14. {
  15.     using (var context = new DatabaseContext())
  16.     {
  17.         return context.Tests.Where(w=>w.Enabled).ToList();
  18.     }
  19. }
  20. catch(Exception e)
  21. {
  22.     // TODO: handle also those ValidationErrors, thrown by Entity Framework
  23.     // so here we get a lot more code
  24.     _logger.Error(e);
  25. }
RAW Paste Data
Top