Advertisement
Guest User

NHibernateRepository

a guest
Jul 16th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using NHibernate;
  6. using NHibernate.Criterion;
  7. using NHibernate.Linq;
  8. using NHibernateUnitOfWork;
  9. using Expression = System.Linq.Expressions.Expression;
  10.  
  11. namespace NHibernateRepository
  12. {
  13.     public class Repository<T> : IRepository<T>
  14.     {
  15.         protected virtual ISession Session
  16.         {
  17.             get { return UnitOfWork.CurrentSession; }
  18.         }
  19.        
  20.         public Expression Expression
  21.         {
  22.             get { return Session.Query<T>().Expression; }
  23.         }
  24.  
  25.         public Type ElementType
  26.         {
  27.             get { return Session.Query<T>().ElementType; }
  28.         }
  29.  
  30.         public IQueryProvider Provider
  31.         {
  32.             get { return Session.Query<T>().Provider; }
  33.         }
  34.  
  35.         public void Add(T entity)
  36.         {
  37.             Session.Save(entity);
  38.         }
  39.  
  40.         public T Get(int id)
  41.         {
  42.             return Session.Get<T>(id);
  43.         }
  44.  
  45.         IEnumerator IEnumerable.GetEnumerator()
  46.         {
  47.             return this.GetEnumerator();
  48.         }
  49.  
  50.         public IEnumerator<T> GetEnumerator()
  51.         {
  52.             return Session.Query<T>().GetEnumerator();
  53.         }
  54.  
  55.         public void Remove(T entity)
  56.         {
  57.             Session.Delete(entity);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement