0
   Profile p = db.Profile.Where(m => m.MemberId == MemberUID).Single();  

   db.Entry(p).State = EntityState.Modified;      
   p.LastUpdatedDate = DateTime.Now;
   db.SaveChanges();

I want to update the LastUpdatedDate but its giving me an error

"The property 'LastUpdatedDate' is part of the object's key information and cannot be modified."

NOTE:LastUpdatedDate is not a primary key it is just set as entity key

I want to update this as it is .. is there any way to do so ? help will be appreciated

Model

 public partial class Profile 
    {

        public System.DateTime LastUpdatedDate { get; set; }

    }
Zain Abbas
  • 111
  • 3
  • 15
  • Can you show the `Model` of where you created the `LastUpdatedDate`? And if you look at the table in SQL, is it a PK? – SS_DBA May 19 '17 at 14:20
  • It is not a primary Key it is set as Entity key in .edmx file – Zain Abbas May 19 '17 at 14:21
  • This might help. http://stackoverflow.com/questions/10138074/whats-entity-key-in-edmx-file – SS_DBA May 19 '17 at 14:23
  • That is a partial class. Where is the rest? If there is none, why would you create a class that only has a single property of a base type with no security or wrapper? – Tipx May 19 '17 at 15:35
  • @Tipx its just an example I only want to update the entity Key value whisch is set as entitiy key in ,edmx file but not in db – Zain Abbas May 23 '17 at 11:53
  • Don't? Primary keys should be immuable. You can technically do it, but you shouldn't. It's a very strong code-smell (more like a design-smell) to me. Also, your entity in the edmx, or the poco class if using a code-first approach, should be very close to the database entity. You can ignore some attribute, but I'd definitely match the primary key. – Tipx May 23 '17 at 15:25

0 Answers0