This commit is contained in:
454313500@qq.com
2021-05-13 01:39:34 +08:00
parent 2e5b991db0
commit fe850bbc2c
53 changed files with 1318 additions and 404 deletions

View File

@@ -1,6 +1,7 @@
using CC.Yi.DALFactory;
using CC.Yi.IBLL;
using CC.Yi.IBLL;
using CC.Yi.IDAL;
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,10 +12,13 @@ namespace CC.Yi.BLL
public class BaseBll<T> : IBaseBll<T> where T : class, new()
{
public IBaseDal<T> CurrentDal;
public BaseBll(IBaseDal<T> cd)
public DbContext DbSession;
public BaseBll(IBaseDal<T> cd, DataContext _Db)
{
CurrentDal = cd;
DbSession = _Db;
}
public IQueryable<T> GetAllEntities()
{
return CurrentDal.GetAllEntities();
@@ -49,37 +53,53 @@ namespace CC.Yi.BLL
return entity;
}
public bool Add(IEnumerable<T> entities)
{
CurrentDal.AddRange(entities);
return DbSession.SaveChanges() > 0;
}
public bool Update(T entity)
{
CurrentDal.Update(entity);
return DbSession.SaveChanges() > 0;
}
public bool Update(T entity, params string[] propertyNames)
{
CurrentDal.Update(entity,propertyNames);
return DbSession.SaveChanges() > 0;
}
public bool Delete(T entity)
{
CurrentDal.Delete(entity);
return DbSession.SaveChanges() > 0;
}
public IDbSession DbSession
{
get
{
return DbSessionFactory.GetCurrentDbSession();
}
}
public bool Delete(int id)
{
CurrentDal.Detete(id);
return DbSession.SaveChanges() > 0;
}
public int DeleteList(List<int> ids)
public bool Delete(IEnumerable<int> ids)
{
foreach (var id in ids)
{
CurrentDal.Detete(id);
}
return DbSession.SaveChanges();//这里把SaveChanges方法提到了循环体外自然就与数据库交互一次
return DbSession.SaveChanges()>0;
}
public bool Delete(Expression<Func<T, bool>> where)
{
IQueryable<T> entities = CurrentDal.GetEntities(where);
if (entities != null)
{
CurrentDal.DeteteRange(entities);
return DbSession.SaveChanges()>0;
}
return false;
}
}

View File

@@ -5,7 +5,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CC.Yi.DALFactory\CC.Yi.DALFactory.csproj" />
<ProjectReference Include="..\CC.Yi.IBLL\CC.Yi.IBLL.csproj" />
<ProjectReference Include="..\CC.Yi.IDAL\CC.Yi.IDAL.csproj" />
</ItemGroup>

View File

@@ -6,14 +6,16 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace CC.Yi.BLL
{
public partial class studentBll : BaseBll<student>, IstudentBll
{
public studentBll(IBaseDal<student> cd):base(cd)
public studentBll(IBaseDal<student> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
}
}
}

View File

@@ -21,6 +21,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace CC.Yi.BLL
{
@@ -28,9 +29,10 @@ namespace CC.Yi.BLL
#>
public partial class <#=k #>Bll : BaseBll<<#=k #>>, I<#=k #>Bll
{
public <#=k #>Bll(IBaseDal<<#=k #>> cd):base(cd)
public <#=k #>Bll(IBaseDal<<#=k #>> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
}
}
<# } #>