Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:42:39+00:00 2026-05-31T07:42:39+00:00

My table Sections (SQL Server) has ID as a primary key (int, identity) and

  • 0

My table Sections (SQL Server) has ID as a primary key (int, identity) and SortIndex column (int) for sorting purposes.

The database has a trigger which sets SortIndex := ID at each INSERT. Obviously I want to change the sorting index later, by swapping the values for two rows.

I access the data using Entity Framework, all with MVC3 web application.

The problem is, Entity Framework doesn’t update the value of SortIndex 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 SortIndex value for this object.

I tried changing StoreGeneratedPattern for this column in EDMX. This seems to be great and elegant but doesn’t solve the problem.

If I set to Identity, it causes EF to properly update the value, but it becomes read only (exception thrown when trying to change). Setting it to Computed is similar, but instead of exception being thrown the values are just not written to the DB.

I can recreate the EF object every time if I need to use it after inserting an object, just by doing:

DatabaseEntities db = new DatabaseEntities()

But it seems like ugly workaround for me.

What’s a solution to this problem?

Obviously something, what doesn’t require me to do some action after every insert (and take a risk that it’s forgotten and unnoticed) is preferred.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:42:40+00:00Added an answer on May 31, 2026 at 7:42 am

    In short StoreGeneratedPattern means: the value is handled by the store and your application will never modify it. In such case you will get store generated value automatically after you call SaveChanges.

    If you don’t use StoreGeneratedPattern you will not get value and you will have to force another query execution to refresh your entity. You can for example do:

    objectContext.Refresh(RefreshMode.StoreWins, yourSection);
    

    Generally situations where you need to update values in both database through triggers and application don’t play very nicely with EF (and probably also other ORM tools).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 database. This database has a Table called Book.
I have the following table in my database: CREATE TABLE [dbo].[XmlData]( [id] [int] IDENTITY(1,1)
I have a table in SQL Server listing corporate departments and their sections and
I have been assigned the task of converting an SQL Server Database to an
What is the easiest way to export to XML from SQL Server [Table or
I need to export data from a SQL database (some groups use SQL Server,
If I make an SQL server database, 1) Do I need to install SQL
I am attempting to programmatically monitor the size of a SQL Server database, so
I have log4net setup and configured to insert into a sql server 2005 table.
I'm using SQL Server 2005 and am sending a Database Mail formatted in HTML.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.