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

  • Home
  • SEARCH
  • 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 9163307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:24:56+00:00 2026-06-17T14:24:56+00:00

I have a table that has an Identity column and another column needs to

  • 0

I have a table that has an Identity column and another column needs to have its value based on the computed identity column.

My EF code looks like this:

var context = new DBEntities();
var newTableRow = new TableRow();
newTableRow.Column1 = newTableRow.ComputedColumn;
context.TableRows.Add(newTableRow);
context.SaveChanges();

If ComputedColumn is an IDENTITY and Column1 is a nullable varchar(50) I would expect the value of Column1 to be the same as the ComputedColumn but it is null.
I have even tried this:

var context = new DBEntities();
var newTableRow = new TableRow();
context.TableRows.Add(newTableRow);
context.SaveChanges();
newTableRow.Column1 = newTableRow.ComputedColumn;
context.SaveChanges();

AND

var context = new DBEntities();
var newTableRow = new TableRow();
context.TableRows.Add(newTableRow);
context.SaveChanges();
var getTableRow = context.TableRows.Single(r => r.ComputedColumn == newTableRow.ComputedColumn);
getTableRow.Column1 = newTableRow.ComputedColumn.ToString();
context.SaveChanges();

Keep in mind that this is part of a larger transaction. What I don’t want to do is complete the transaction then in a separate transaction do another update. I would like to keep everything in one transaction. This had been working in an insert proc before.

Thanks,

Brett

  • 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-06-17T14:24:57+00:00Added an answer on June 17, 2026 at 2:24 pm

    Your second an third example should work if ComputedColumn has DatabaseGeneratedOption.Identity. But they have separate transactions, which you don’t want.

    Your first example can’t work. When a column has DatabaseGeneratedOption.Identity, EF reads the identity value back when executing SaveChanges. It is not aware of any special instruction you might have tried to convey with

    newTableRow.Column1 = newTableRow.ComputedColumn;
    

    As for EF, it’s just an assignment with an empty value.

    Maybe the best alternative is to add a computed column to your database table. You will kill two birds with one stone:

    • It is transactional, because the computed column just re-displays the identity column
    • You prevent redundancy and possible value conflicts.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has an identity column as the Primary Key. None
I have a table that has a single identity column. What is the SQL
I have a table that stores user information. The table has a userid (identity)
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a table which has no identity column. I want to change a
I have a stored procedure that inserts a record which has Identity column. Immediately
I have a SQL Server 2005 database. Table A has an identity column in
I have an old table with a few rows that has a datetime column.
I have an invoice table that has InvoiceID (int identity ) Primary key. and
I'm using Entity Framework 4.1 Code First and I have a table that has

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.