v3.0.0
This commit is contained in:
橙子
2021-05-31 21:41:27 +08:00
parent 8aa1065b37
commit 2bd67778bf
127 changed files with 3895 additions and 8 deletions

106
CC.Yi/CC.Yi.BLL/BaseBll.cs Normal file
View File

@@ -0,0 +1,106 @@
using CC.Yi.IBLL;
using CC.Yi.IDAL;
using CC.Yi.Model;
using Microsoft.EntityFrameworkCore;
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 DbContext DbSession;
public BaseBll(IBaseDal<T> cd, DataContext _Db)
{
CurrentDal = cd;
DbSession = _Db;
}
public IQueryable<T> GetAllEntities()
{
return CurrentDal.GetAllEntities();
}
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 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 bool Delete(int id)
{
CurrentDal.Detete(id);
return DbSession.SaveChanges() > 0;
}
public bool Delete(IEnumerable<int> ids)
{
foreach (var id in ids)
{
CurrentDal.Detete(id);
}
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

@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<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>

29
CC.Yi/CC.Yi.BLL/T4BLL.cs Normal file
View File

@@ -0,0 +1,29 @@

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;
using Microsoft.EntityFrameworkCore;
namespace CC.Yi.BLL
{
public partial class studentBll : BaseBll<student>, IstudentBll
{
public studentBll(IBaseDal<student> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
}
}
public partial class propBll : BaseBll<prop>, IpropBll
{
public propBll(IBaseDal<prop> cd,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
}
}
}

39
CC.Yi/CC.Yi.BLL/T4BLL.tt Normal file
View File

@@ -0,0 +1,39 @@
<#@ 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;
using Microsoft.EntityFrameworkCore;
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,DataContext _Db):base(cd,_Db)
{
CurrentDal = cd;
DbSession = _Db;
}
}
<# } #>
}