c# - EF Entity Can not be updated or deleted -
i building task management ( day day task management, not system tasks).
here tasklistentity
- in table taskid
pk
public partial class tasklist { public int taskid { get; set; } public int userid { get; set; } public string tasktype { get; set; } public string tasknote { get; set; } public string handlerid { get; set; } public int priority { get; set; } public nullable<system.datetime> duedate { get; set; } public nullable<int> remind { get; set; } public string tasksubtype { get; set; } public bool completed { get; set; } public string taskdescription { get; set; } public string handlerid2 { get; set; } public string handlerid3 { get; set; } public string handlerid4 { get; set; } public virtual user user { get; set; } }
when user ticks completed, want update instance did this
unitofwork uow = new unitofwork(); tasklist task = uow.tasks.getall().where(t => t.taskid == taskid).firstordefault(); task.completed = true; uow.tasks.update(task); uow.complete();
i'm getting weird error
system.invalidoperationexception: 'the property 'completed' part of object's key information , cannot modified. '
the property completed
no key , not fk. can't think of why happening. missing here? added see if helps
[key] public int taskid { get; set; }
just make sure system sees taskid
primary key not completed
field.
i have been battling hours now. can please me?
here update method
public void update(tentity entity) { try { context.entry(entity).state = system.data.entity.entitystate.modified; } catch (dbentityvalidationexception dbex) { foreach (var validationerrors in dbex.entityvalidationerrors) { foreach (var validationerror in validationerrors.validationerrors) { trace.traceinformation("class: {0}, property: {1}, error: {2}", validationerrors.entry.entity.gettype().fullname, validationerror.propertyname, validationerror.errormessage); } } } }
Comments
Post a Comment