Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework doesn't update value which is modified by a trigger
    primarykey
    data
    text
    <p>My table <code>Sections</code> (SQL Server) has <code>ID</code> as a primary key <code>(int, identity)</code> and <code>SortIndex</code> column (int) for sorting purposes.</p> <p>The database has a trigger which sets <code>SortIndex := ID</code> at each <code>INSERT</code>. Obviously I want to change the sorting index later, by swapping the values for two rows.</p> <p>I access the data using Entity Framework, all with MVC3 web application.</p> <p>The problem is, Entity Framework doesn't update the value of <code>SortIndex</code> after I insert a new object into the table. It also caches all the data, so the following call to get all objects from this table will also give wrong <code>SortIndex</code> value for this object.</p> <p>I tried changing <code>StoreGeneratedPattern</code> for this column in <code>EDMX</code>. This seems to be great and elegant but doesn't solve the problem.</p> <p>If I set to <code>Identity</code>, it causes EF to properly update the value, but it becomes read only (exception thrown when trying to change). Setting it to <code>Computed</code> is similar, but instead of exception being thrown the values are just not written to the DB.</p> <p>I can recreate the EF object every time if I need to use it after inserting an object, just by doing:</p> <pre><code>DatabaseEntities db = new DatabaseEntities() </code></pre> <p>But it seems like ugly workaround for me.</p> <p>What's a solution to this problem?</p> <p>Obviously something, what doesn't require me to do some action after every <code>insert</code> (and take a risk that it's forgotten and unnoticed) is preferred. </p>
    singulars
    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.
 

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