/// <summary> /// 获取单个实体 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <returns></returns> public static TEntity getEntryById <TEntity, T>(T id) where TEntity : class { using (MyDataContext _db = new MyDataContext()) { return(_db.Set <TEntity>().Find(id)); } }
/// <summary> /// 修改实体 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="entry"></param> /// <param name="ID"></param> public static void EditProjectEntry <TEntity>(TEntity entity, string ID) where TEntity : class { using (MyDataContext _db = new MyDataContext()) { _db.UpdateProjectByProperty <TEntity>(entity, ID); } }
/// <summary> /// 删除实体 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="entry"></param> public static void DeleteEntry <TEntity>(TEntity entity) where TEntity : class { using (MyDataContext _db = new MyDataContext()) { _db.Set <TEntity>().Attach(entity); _db.Set <TEntity>().Remove(entity); _db.SaveChanges(); } }
public static bool AddModel <TEntity>(List <TEntity> entry) where TEntity : class { using (MyDataContext _db = new MyDataContext()) { _db.Set <TEntity>().AddRange(entry); _db.SaveChanges(); return(true); } }
public static TEntity AddModel <TEntity>(TEntity entry) where TEntity : class { using (MyDataContext _db = new MyDataContext()) { _db.Set <TEntity>().Add(entry); _db.SaveChanges(); return(entry); } }