Doraemon
Doraemon

Reputation: 53

Entity Framework: Insert a new record and Update information of this record

I don't know how I can handle this situation, Can you help me ?

a. I insert a new record to a table

var news = new News();

News.Title = "Hello World";

myRepository.InsertNews(catId,news);

In InsertNews() function, I call myDbContext.SaveChanges(); and new record is inserted into database. In this time, I already have Id of new record.

b. After I have id of new records, I need do call other functions to process some business and get data back to update new record.

news.Metadata = newData;

and I call myDbContext.SaveChanges();

My system displays an error message. The property 'Id' is part of the object's key information and cannot be modified.

Please help me resolve this issue. Thanks

Upvotes: 0

Views: 2055

Answers (1)

Related Questions