Note that there are some explanatory texts on larger screens.

plurals
  1. POEF Code-First doesn't update Sets immediately
    primarykey
    data
    text
    <p>I'm developing an ASP.NET MVC 3 website with Entity Framework Code-First. What's happening is that in the Index action, I get some TransactionJournal objects from the database, call a method called CreateTransactions(), that, basically, create some transactions and add them to the ICollection in the TransactionJournal. Then, I save the context, and then query for all Transactions, and then they are not there! But if I just refresh the page, I will get the transactions generated at the first time, that didn't appear, but not the ones from this time. There's a lot of code, so, I'll try to mock the parts that are important here so that you can see.</p> <p>A piece of the TransactionJournal:</p> <pre><code>public class TransactionJournal { public long TransactionJournalID { get; set; } public virtual ICollection&lt;Transaction&gt; Transactions { get; set; } // ... } </code></pre> <p>A piece of the Index action:</p> <pre><code>IDbSet&lt;TransactionJournal&gt; journal_dbset = Context.Set&lt;TransactionJournal&gt;(); ICollection&lt;TransactionJournal&gt; journals = journal_dbset.Where( ... ).ToList(); foreach(TransactionJournal j in journals) j.CreateTransactions(); // Create some transactions and add it to the Transactions collection Context.Commit(); // This actually calls the SaveChanges() method, only IDbSet&lt;Transaction&gt; trans_dbset = Context.Set&lt;Transaction&gt;(); ICollection&lt;Transaction&gt; trans = trans_dbset.Where( ... ).ToList(); // The transactions just created are NOT here! But those created in previews Index action calls are! </code></pre> <p>It's like if the SaveChanges() don't immediately updates the Sets in the Context object. What should I do to get these just created transactions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload