예제 #1
0
 public void Save <T>(List <T> item) where T : class
 {
     using (FitnessContext db = new FitnessContext())
     {
         db.Set <T>().AddRange(item);
         db.SaveChanges();
     }
 }
예제 #2
0
 public void Save <T>(string fileName, T item) where T : class
 {
     using (var db = new FitnessContext())
     {
         if (item is List <User> )
         {
             db.Users.AddRange(item as List <User>);
         }
         if (item is List <Food> )
         {
             db.Foods.AddRange(item as List <Food>);
         }
         if (item is Eating)
         {
             db.Eatings.Add(item as Eating);
         }
         if (item is Gender)
         {
             db.Genders.Add(item as Gender);
         }
         db.SaveChanges();
     }
 }