コード例 #1
0
 public void RemoveItem <T>(object item) where T : class
 {
     using (var db = new MediaPlayerDbContext())
     {
         db.Remove(item as T);
         db.SaveChanges();
     }
 }
コード例 #2
0
 public int AddItem <T>(object item) where T : class
 {
     using (var db = new MediaPlayerDbContext())
     {
         db.Add(item as T);
         db.SaveChanges();
         return((item is AbstractObjectWithID) ? (item as AbstractObjectWithID).Id : 0);
     }
 }
コード例 #3
0
 public void UpdateItem <T>(object item) where T : class
 {
     using (var db = new MediaPlayerDbContext())
     {
         if (item is Tag)
         {
             var tag = item as Tag;
             if (tag.ParentTag != null && tag.ParentTag.Id < 0)
             {
                 tag.ParentTag = null;
                 db.Entry(item).Reference("ParentTag").IsModified = true;
             }
         }
         db.Update(item as T);
         db.SaveChanges();
     }
 }