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 6362553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:55:24+00:00 2026-05-24T23:55:24+00:00

I am working on an application using Entity Framework 4.1 with DbContext API, in

  • 0

I am working on an application using Entity Framework 4.1 with DbContext API, in a disconnected environment. I have two basic entities, Person and Degree. Degree has a non-mandatory one-to-many relationship to Person.

The issue is occurring when I update the DegreeId property on the Person entity to a different value. When I save the changes, EF generates an Update statement on the actual Degree table. This in turn causes a concurrency error violation when two or more users are using the application. I was able to find the issue while using SQL Profiler. I’ve tried several configuration variations using the Fluent API, but nothing seems to suppress the additional Update statement on the Degree table.

Here are my entities:

public partial class Person
    {
        public int PersonId { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public Nullable<int> DegreeId { get; set; }

        public Degree Degree { get; set; }
    }

public partial class Degree 
    {
        public int DegreeId { get; set; }
        public string Name { get; set; }
    }

In my Repository class, I am loading the Person object graph as such:

public override Person GetById(int id)
   {
         return DataContext.People
                    .Include(d => d.Degree)
                    .FirstOrDefault(x => x.PersonId == id);
   }

In my Service layer, I am getting a person record, and then updating the DegreeId property to a specific value. Note: UnitOfWork.Commit method exposes SaveChanges on DbContext.

using (var unitOfWork = IoC.Resolve<IUnitOfWork>())
  {
        var personRepository = new PersonRepository(unitOfWork);
        var person = personRepository.GetById(240);
        person.DegreeId = 1;
        personRepository.Update(person);
        unitOfWork.Commit();
  }

My repository update method attaches the person entity and marks the entity state as modified:

var state = DataContext.Entry(entity).State;
dbSet.Attach(entity);
DataContext.Entry(entity).State = EntityState.Modified; 

Here is the SQL statement found in the Profiler session:

exec sp_executesql N'declare @p int
update [Client].[Degree]
set @p = 0
where (([DegreeId] = @0) and ([RowVersion] = @1))
select [RowVersion]
from [Client].[Degree]
where @@ROWCOUNT > 0 and [DegreeId] = @0',N'@0 int,
@1 binary(8)',@0=1,@1=0x0000000000004469

Does anyone know how to stop EF from sending this update statement to SQL Server? Is there something apparent in my entity configuration that causes EF to assume the Degree is also affected?

Thank you.

  • 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-24T23:55:25+00:00Added an answer on May 24, 2026 at 11:55 pm

    I was able to find the cause of this issue and prevent it from occurring, but I cannot really explain why it was occurring.

    My tables include a TimeStamp column and a corresponding property in the base class for my entities.
    I did not show the base class in my original question because it only includes the RowVersion and other audit properties, which I assumed were irrelevant.
    One would think I would’ve learned by know not assume anything about Entity Framework.

    Here is my base class definition for the Degree entity:

    public abstract class EntityBase : ValidableObject, IEntityBase
    {
        public virtual byte[] RowVersion { get; protected set; }
        public virtual DateTime? CreateDate { get; set; }
        public virtual string CreateUser { get; set; }
        public virtual DateTime? ModifyDate { get; set; }
        public virtual string ModifyUser { get; set; }
    }
    

    Here is my context model configuration for the Degree entity:

    internal class DegreeConfiguration : EntityTypeConfiguration<Degree>
        {
            internal DegreeConfiguration()
                : base()
            {
                ToTable("Degree", "dbo");
                Property(x => x.RowVersion).IsRowVersion();
            }
        }
    

    Because of my application requirements, I must load the Person entity using the Include method to eagerly load the Degree entity so the object graph is
    fully populated when the consumer requests the entity.

    return ctx.People.Include(p => p.Degree).Where(x => x.PersonId == id).First();
    

    When the DegreeId property of the Person object is modified and attached to the Context, the following Update statement is generated
    upon calling SaveChanges():

    exec sp_executesql N'declare @p int
    update [dbo].[Degree]
    set @p = 0
    where (([DegreeId] = @0) and ([RowVersion] = @1))
    select [RowVersion]
    from [dbo].[Degree]
    where @@ROWCOUNT > 0 and [DegreeId] = @0',N'@0 int,
    @1 binary(8)',@0=2,@1=0x00000000000007DF
    

    This is occurring even though I am not knowingly updating the Degree entity and causes havoc when two or more users using the application simultaneously.

    To suppress the Update statement from being generated on the Degree navigation property, I commented out the concurrency check on the model configuration as such:

    internal class DegreeConfiguration : EntityTypeConfiguration<Degree>
        {
            internal DegreeConfiguration()
                : base()
            {
                ToTable("Degree", "dbo");
                //Property(x => x.RowVersion).IsRowVersion();
            }
        }
    

    Upon re-executing the process, EF no longer generates the problematic Update statement.

    I’ve done a considerable number of searches both on MS site for EF 4.1, as well as general Google searches. I cannot come up with any concrete explanations.

    Thank you.

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

Sidebar

Related Questions

I have an application I am working on, using Entity Framework 4.1 as my
I am using Entity Framework in an application i am working on, however when
I am working on an MVC application using Entity Framework. After creating an EDMX,
I am working on a WPF application using Entity Framework 4.0. When I tried
I'm working on a MVC3 application and i'm using the Entity Framework linked to
I am using Entity Framework 4 in a desktop application with SQL Compact. I
I have been using Entity Framework CTP with Code-First as in this tutorial by
I'm using the Entity Framework as my ORM for an ASP.Net (webforms) application. Suppose
I'm working on a .NET 4 application, C#, Entity Framework 4, SQL Server 2008.
I have a small VB.NET application that I'm working on using the full version

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.