PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Bifrost.RavenDb.Embeddable/EntityContext.cs

#
C# | 59 lines | 47 code | 12 blank | 0 comment | 0 complexity | 11dc529952258b42686ce38d94fb5f39 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using Bifrost.Entities;
  2. using System.Linq;
  3. using Raven.Client.Embedded;
  4. using Raven.Client;
  5. namespace Bifrost.RavenDb.Embeddable
  6. {
  7. public class EntityContext<T> : IEntityContext<T>
  8. {
  9. IEntityContextConnection _connection;
  10. IDocumentSession _session;
  11. public EntityContext(EntityContextConnection connection)
  12. {
  13. _connection = connection;
  14. _session = connection.DocumentStore.OpenSession();
  15. }
  16. public IQueryable<T> Entities { get { return _session.Query<T>(); } }
  17. public void Attach(T entity)
  18. {
  19. }
  20. public void Insert(T entity)
  21. {
  22. _session.Store(entity);
  23. }
  24. public void Update(T entity)
  25. {
  26. _session.Store(entity);
  27. }
  28. public void Delete(T entity)
  29. {
  30. _session.Delete(entity);
  31. }
  32. public void Save(T entity)
  33. {
  34. _session.Store(entity);
  35. _session.SaveChanges();
  36. }
  37. public void Commit()
  38. {
  39. _session.SaveChanges();
  40. }
  41. public void Dispose()
  42. {
  43. _session.SaveChanges();
  44. _session.Dispose();
  45. }
  46. }
  47. }