1.先把登录模板和首页模板放进去,然后把要用的js和cs设置好
2.选中model实体层点击新建项目选中ADO.Net实体数据模型把数据库里面的表应用进来
3.在数据访问层添加BaseRepository类,包括一些增删改的一些方法
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace X_admin.DAL
{
public class BaseRepository<T, TS> where T : class
where TS : DbContext, new()
{
private DbContext db = DbContextFactory<TS>.GetCurrentDbContext();
//添加单条记录
public bool Add(T entily)
{
db.Set<T>().Add(entily);
return db.SaveChanges() > 0;
}
//添加多条记录
public bool AddList(List<T> entily)
{
db.Set<T>().AddRange(entily);
return db.SaveChanges() > 0;
}
//删除
public bool Delete(T entity)
{
db.Entry(entity).State = EntityState.Deleted;
return db.SaveChanges() > 0;
}
public virtual bool Delete(int id)
{
var entity = db.Set<T>().Find(id);//如果实体已经在内存中,那么就直接从内存拿,如果内存中跟踪实体没有,那么才查询数据库。
if (entity != null) db.Set<T>().Remove(entity);
return db.SaveChanges() > 0;
}
//删除多个
public bool BDELETE(List<T> entiles)
{
db.Set<T>().RemoveRange(entiles);
return db.SaveChanges() > 0;
}
//根据id删除
public bool BatchDELETE(params int[] entiles)