Search code examples
c#databasesilverlightwindows-phone-7sqlmetal

selective get and delete posts from database


In my windows phone 7 app i have database-class generated by sqlmetal. in addition, i have class that helps to work with this database.

    public static IList<Task> GetTasks()
    {
        IList<Task> tasks = new List<Task>();
        using (var context = new MyDBContext(ConnectionString))
        {
           tasks = (from emp in context.Tasks select emp).ToList();
        }
        return tasks;
    }

this code return all posts from the database.

My questions:

  • 1) How I can get posts, for example, only with a specific date (datetime) or ID(int)?
  • 2) Is there any way to delete posts from the database?

Solution

  • Try this:

    tasks = from emp in context.Tasks 
            where emp.ID == yourId
            select emp;
    

    To delete posts from te databse use DeleteOnSubmit(entity) method like:

    context.Tasks.Attach(entityToDelete);
    context.Tasks.DeleteOnSubmit(entityToDelete);
    context.SubmitChanges();