A factory to create an instance of the TasksContext
예제 #1
0
 public Task FindByName(string taskName)
 {
     using (var context = TasksContextFactory.Create(_connectionString))
     {
         return(context.Tasks.FirstOrDefault(t => t.TaskName == taskName));
     }
 }
예제 #2
0
 public Task FindById(int taskId)
 {
     using (var context = TasksContextFactory.Create(_connectionString))
     {
         return(context.Tasks.FirstOrDefault(t => t.Id == taskId));
     }
 }
예제 #3
0
 public IEnumerable <Task> FindAll()
 {
     using (var context = TasksContextFactory.Create(_connectionString))
     {
         return(context.Tasks.ToList());
     }
 }
예제 #4
0
 public void Clear()
 {
     using (var context = TasksContextFactory.Create(_connectionString))
     {
         context.Tasks.RemoveRange(context.Tasks);
         context.SaveChanges();
     }
 }
예제 #5
0
 public void Update(Task task)
 {
     using (var context = TasksContextFactory.Create(_connectionString))
     {
         context.Update(task);
         context.SaveChanges();
     }
 }
예제 #6
0
        public Task Add(Task newTask)
        {
            using (var context = TasksContextFactory.Create(_connectionString))
            {
                var task = context.Add(newTask);
                context.SaveChanges();

                return(task.Entity);
            }
        }