v1.0.0
This commit is contained in:
87
CC.Yi.BLL/BaseBll.cs
Normal file
87
CC.Yi.BLL/BaseBll.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CC.Yi.DALFactory;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
public class BaseBll<T> : IBaseBll<T> where T : class, new()
|
||||
{
|
||||
public IBaseDal<T> CurrentDal;
|
||||
public BaseBll(IBaseDal<T> cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
}
|
||||
//public abstract void SetCurrentDal();
|
||||
//public BaseBll()//基类的构造方法
|
||||
//{
|
||||
// SetCurrentDal();//该方法由子类去实现
|
||||
//}
|
||||
|
||||
public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda)
|
||||
{
|
||||
return CurrentDal.GetEntities(whereLambda);
|
||||
}
|
||||
|
||||
public int GetCount(Expression<Func<T, bool>> whereLambda) //统计数量
|
||||
{
|
||||
return CurrentDal.GetCount(whereLambda);
|
||||
}
|
||||
|
||||
public IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda) //分组
|
||||
{
|
||||
return CurrentDal.GetGroup(whereLambda, groupByLambda);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
|
||||
{
|
||||
return CurrentDal.GetPageEntities(pageSize, pageIndex, out total, whereLambda, orderByLambda, isAsc);
|
||||
}
|
||||
|
||||
public T Add(T entity)
|
||||
{
|
||||
CurrentDal.Add(entity);
|
||||
DbSession.SaveChanges();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public bool Update(T entity)
|
||||
{
|
||||
CurrentDal.Update(entity);
|
||||
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)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
CurrentDal.Detete(id);
|
||||
}
|
||||
return DbSession.SaveChanges();//这里把SaveChanges方法提到了循环体外,自然就与数据库交互一次
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
32
CC.Yi.BLL/CC.Yi.BLL.csproj
Normal file
32
CC.Yi.BLL/CC.Yi.BLL.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</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>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4BLL.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4BLL.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="T4BLL.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4BLL.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
19
CC.Yi.BLL/T4BLL.cs
Normal file
19
CC.Yi.BLL/T4BLL.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
public partial class studentBll : BaseBll<student>, IstudentBll
|
||||
{
|
||||
public studentBll(IBaseDal<student> cd):base(cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
CC.Yi.BLL/T4BLL.tt
Normal file
37
CC.Yi.BLL/T4BLL.tt
Normal file
@@ -0,0 +1,37 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
string txt;
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
|
||||
txt=sr.ReadToEnd();
|
||||
sr.Close();
|
||||
string[] ModelData= txt.Split(',');
|
||||
#>
|
||||
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.IDAL;
|
||||
using CC.Yi.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.BLL
|
||||
{
|
||||
<# foreach(string k in ModelData){
|
||||
#>
|
||||
public partial class <#=k #>Bll : BaseBll<<#=k #>>, I<#=k #>Bll
|
||||
{
|
||||
public <#=k #>Bll(IBaseDal<<#=k #>> cd):base(cd)
|
||||
{
|
||||
CurrentDal = cd;
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
Reference in New Issue
Block a user