OA.BLL/BaseService.cs

(完整代码) 1KB

using OA.DALFactory;
using OA.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;

namespace OA.BLL
{
    public abstract class BaseService<T> where T :class,new()
    {
        public IDbSession DbSession//为什么要抽象?理解去
        {
            //get { return new DbSession(); }//没有必要在每个业务操作类里都new一次
            get { return DbSessionFactory.CreateDbSession(); }
        }
        /****************通过子类DbSession拿到****************/
        public IBaseDal<T> CurrentDal { get; set; }
        public abstract void SetCurrentDal();
        public BaseService()
        {
            SetCurrentDal();
        }
        /****************************************************/
        public IQueryable<T> LoadEntities(Expression<Func<T, bool>> whereLabda)
        {
            return this.CurrentDal.LoadEntities(whereLabda);
        }
        public IQueryable<T> LoadPageEntities<s>(int pageIndex,int pageSize,out int totalCount,Expression<Func<T,bool>>whereLambda,Expression<Func<T,s>>orderbyLambda,bool isAsc)
        {
            return this.CurrentDal.LoadPageEntities<s>(pageIndex,pageSize,out totalCount,whereLambda,orderbyLambda,isAsc);
        }
        public bool DeleteEntity(T entity)
        {
            this.CurrentDal.DeleteEntities(entity);
            return this.DbSession.SaveChanges();
        }
        public bool UpdateEntity(T entity)
        {
            this.CurrentDal.UpdateEntities(entity);
            return this.DbSession.SaveChanges();
        }
        public T AddEntity(T entity)
        {
            this.CurrentDal.AddEntities(entity);
             this.DbSession.SaveChanges();
            return entity;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。