123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using Bowin.Common.Data;
- using Bowin.Common.Linq.Entity;
- namespace EMIS.DataLogic.Repositories.Log
- {
- public class LogRepository<TEntity> where TEntity : class
- {
- private LogUnitOfWork _unitOfWork;
- private LogRepository()
- {
- }
- public LogRepository(LogUnitOfWork unitOfWork)
- {
- this._unitOfWork = unitOfWork;
- }
- public TEntity GetSingle(Expression<Func<TEntity, bool>> expression)
- {
- return this.Entities.Where<TEntity>(expression).FirstOrDefault<TEntity>();
- }
- public TEntity GetSingle(Expression<Func<TEntity, bool>> expression, params string[] paths)
- {
- IQueryable<TEntity> source = this.Entities;//.Include(path)
- foreach (var path in paths)
- {
- source = source.Include(path);
- }
- return source.Where<TEntity>(expression).FirstOrDefault<TEntity>();
- }
- public TEntity GetSingle(Expression<Func<TEntity, bool>> expression, params Expression<Func<TEntity, object>>[] paths)
- {
- IQueryable<TEntity> source = this.Entities;//.Include(path)
- foreach (var path in paths)
- {
- source = source.Include(path);
- }
- return source.Where<TEntity>(expression).FirstOrDefault<TEntity>();
- }
- public IQueryable<TEntity> Entities
- {
- get
- {
- return this._unitOfWork.Set<TEntity>();
- }
- }
- public LogUnitOfWork UnitOfWork
- {
- get
- {
- return this._unitOfWork;
- }
- }
- public GridResultSet<TEntity> GetPagedList<S>(Expression<Func<TEntity, bool>> expression, int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderBy, bool descending, params Expression<Func<TEntity, object>>[] paths)
- {
- IQueryable<TEntity> source = this.Entities;//.Include(path)
- foreach (var path in paths)
- {
- source = source.Include(path);
- }
- source = source.Where<TEntity>(expression);
- source = descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
- GridResultSet<TEntity> gridResult = new GridResultSet<TEntity>();
- gridResult.rows = source.Skip<TEntity>((pageIndex) * pageSize).Take<TEntity>(pageSize).ToList();
- gridResult.total = source.Count();
- return gridResult;
- }
- public GridResultSet<TEntity> GetPagedList<S>(Expression<Func<TEntity, bool>> expression, int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderBy, bool descending)
- {
- try
- {
- IQueryable<TEntity> source = this.Entities.Where<TEntity>(expression);
- source = descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
- GridResultSet<TEntity> gridResult = new GridResultSet<TEntity>();
- gridResult.rows = source.Skip<TEntity>((pageIndex) * pageSize).Take<TEntity>(pageSize).ToList();
- gridResult.total = source.Count();
- return gridResult;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public IQueryable<TEntity> GetList<S>(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, S>> orderBy, bool descending)
- {
- var source = GetList(expression);
- return descending ? source.OrderByDescending<TEntity, S>(orderBy) : source.OrderBy<TEntity, S>(orderBy);
- }
- public IQueryable<TEntity> GetList(Expression<Func<TEntity, bool>> expression)
- {
- return this.Entities.Where<TEntity>(expression);
- }
- }
- }
|