0

I want to modify some fields after query, but the return value is changed after I modified the fields.

I want to keep the IQueryable value after I modify it.

How can I store the IQueryable value?

public IQueryable<Book> GetBook(int id)
    {
        IQueryable<Book> Books = null;
        IQueryable<Book> Book_return = null;

       Books = db.Book.Where(u => u.id == id && u.is_read != true);

        Book_return = Books;

        foreach (var item in Books)
        {

            item.read_time = DateTime.Now;
            item.is_read = true;
            db.Entry(item).State = EntityState.Modified;
        }

        try
        {
            db.SaveChanges();
        }
        catch (DbUpdateConcurrencyException)
        {
            throw;
        }

        return Book_return;
    }

1 Answer 1

1

You could use:

IEnumerable<Book> Book_return = null    
Book_return = Books.ToList();

And the return type of the method must be a IEnumerable<Book>,

2
  • 1
    IEnumerable<Book> Book_return = null; Book_return = Books.ToList();
    – Sha-Pai Li
    May 12, 2015 at 7:50
  • @Sha-PaiLi You are off course right. But you should also change the return type of your action. May 12, 2015 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.