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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:36+00:00 2026-05-30T01:44:36+00:00

I am inserting a new row to the database table using Entity Framework, but

  • 0

I am inserting a new row to the database table using Entity Framework, but my problem is that column ValidFromDate is causing an exception

The property ‘ValidFromDate’ is part of the object’s key information
and cannot be modified date

Our DBA has defined database and image below is the snapshot of the EDMX file. ValidFromDate is a datetime column.

Idea of the FarmAnimal is to track the history of where certain animal has been. Therefore AnimalId and ValidFromDate causes the row to be unique.

Now the question is that how can I can insert new row to the table that has this kind of schema?

EDMX

Insert using Entity Framework

var farmAnimal = new FarmAnimal {
   AnimalId = insert.AnimalId,
   ValidFromDate = insert.ValidFromDate // exception comes from this line,
   etc.
};
entities.FarmAnimals.Add(farmAnimal);

Update: StackTrace

   at System.Data.Objects.EntityEntry.DetectChangesInProperties(Boolean detectOnlyComplexProperties)
   at System.Data.Objects.ObjectStateManager.DetectChangesInScalarAndComplexProperties(IList`1 entries)
   at System.Data.Objects.ObjectStateManager.DetectChanges()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
   at System.Data.Entity.DbSet`1.Add(TEntity entity)
   at xxx.Repositories.PairingRepository.UpdateFarmAnimals(IEnumerable`1 updates, IEnumerable`1 inserts) in xxx
   at xxx.Services.PairingService.RemovePairingAnimals(List`1 animalIds) in xxx
   at xxx.Controllers.PairingController.RemovePairingAnimals(List`1 animalIds) in xxx
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

Update 2: Entity Framework files

I have added three files Entity Framework mapping files / generators
EDMX file
ADO.NET DbContext Generator
ADO.NET EntityObject Generator (POCO’s)

  • 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-30T01:44:37+00:00Added an answer on May 30, 2026 at 1:44 am

    The DbSet wrapper fails before it even does anything with your new FarmAnimal – DetectChanges is called before AddObject on the underlying ObjectContext, and it somehow detects forbidden changes in a FarmAnimal already loaded/added to the context. If you’re using POCOs with proxies or just plain boring classes generated with change tracking (that’s NOT the same as “Self-Tracking Entities”, just the classes that get generated when you add a new data model with vanilla VS2010), you can turn off automatic detection of changes so that it does not get called.

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

Sidebar

Related Questions

I am having a problem with inserting a new row in database using Doctrine
I'm inserting new rows into a SQLite table, but I don't want to insert
I have a trigger that is fire on inserting a new record in table
When inserting a new row in a table T, I would like to check
After inserting new html to DOM,I need to add some listeners to it. But
So the main program is in C#. Inserting new records into a VFP database
I have a non-nullable database column which has a default value set. When inserting
I m using Spring's HibernateDAOSupport class to handle my DAO. my problem is that
An external application come to my database for inserting row in a Sql server
I have a small SQL CE 4.0 database with several tables, mapped using Entity

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.