i am using entity frame work 5 database first workflow, just my first attempt, i am trying to update a record attribute, but it doesn't seem to work, the error message is:
the property 'device_name' is part of the object's key information and cannot be modified
here is my code:
device dev = dbEntities.devices.First( i => i.id==1 );
dev.device_name="newUpdateValue";
dbEntities.SaveChanges( );
also tried this:
protected int UpdateMethod(int Id, string newValue,string modelNumber)
{
using (var ctx = new GSC_NewSchoolCoreEntities( ) )
{
var query = ( from q in ctx.devices
where q.id == Id
select q ).First( );
query.device_name = newValue;
query.model_number= modelNumber;
int result = ctx.SaveChanges( );
return result;
}
}
the calling method:
UpdateMethod( DeviceID, DeviceName, ModelNumber );
still having the same error message, i have search online to see if i could fix this myself, but none of the online solutions work for me! device_name and model_number are what i want to update but not the id, Please is there anything i am missing? Thanks for your contributions.