Example #1
0
 /// <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));
     }
 }
Example #2
0
 /// <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);
     }
 }
Example #3
0
 /// <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();
     }
 }
Example #4
0
 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);
     }
 }
Example #5
0
 public static TEntity AddModel <TEntity>(TEntity entry) where TEntity : class
 {
     using (MyDataContext _db = new MyDataContext())
     {
         _db.Set <TEntity>().Add(entry);
         _db.SaveChanges();
         return(entry);
     }
 }