-
-
Save KingsleyOmon-Edo/413e6cbd2222e0713d42e801ca46b162 to your computer and use it in GitHub Desktop.
Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using NHibernate; | |
using NHibernate.Linq; | |
namespace BMobile.Infrastructure.Entitys | |
{ | |
public class Repository : IRepository | |
{ | |
private readonly ISession _session; | |
public Repository(ISession session) | |
{ | |
_session = session; | |
} | |
public T Get<T>(int id) where T : IEntity | |
{ | |
return _session.Get<T>(id); | |
} | |
public void Save<T>(T entity) where T : IEntity | |
{ | |
_session.SaveOrUpdate(entity); | |
} | |
public void Delete<T>(T entity) where T : IEntity | |
{ | |
_session.Delete(entity); | |
} | |
public T Execute<T>(IQuery<T> query) | |
{ | |
return query.Execute(_session); | |
} | |
public IQueryable<T> Query<T>(Expression<Func<T, bool>> predicate) | |
{ | |
return _session.Query<T>().Where(predicate); | |
} | |
public IEnumerable<T> PagedQuery<T>(int startIndex, int count, Expression<Func<T, bool>> predicate) | |
{ | |
var query = _session.Query<T>().Where(predicate); | |
query.Skip(startIndex).Take(count); | |
return query.ToList<T>(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using NHibernate; | |
using NHibernate.Linq; | |
namespace BMobile.Infrastructure.Entitys | |
{ | |
public class Repository : IRepository | |
{ | |
private readonly ISession _session; | |
public Repository(ISession session) | |
{ | |
_session = session; | |
} | |
public T Get<T>(int id) where T : IEntity | |
{ | |
return _session.Get<T>(id); | |
} | |
public void Save<T>(T entity) where T : IEntity | |
{ | |
_session.SaveOrUpdate(entity); | |
} | |
public void Delete<T>(T entity) where T : IEntity | |
{ | |
_session.Delete(entity); | |
} | |
public T Execute<T>(IQuery<T> query) | |
{ | |
return query.Execute(_session); | |
} | |
public IQueryable<T> Query<T>(Expression<Func<T, bool>> predicate) | |
{ | |
return _session.Query<T>().Where(predicate); | |
} | |
public IEnumerable<T> PagedQuery<T>(int startIndex, int count, Expression<Func<T, bool>> predicate) | |
{ | |
var query = _session.Query<T>().Where(predicate); | |
query.Skip(startIndex).Take(count); | |
return query.ToList<T>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment