dynamics crm 2011 - Data Stored in Session Will not Detect Context Attachment Correctly -


i have list of custom entity store in session user can page through data in asp.net mvc website. user not editing list, approves after through everything.

 list<scholarship> ss = x.scholarshipset.where(m => m.requriements != null).tolist();   session["listofscholarships"] = ss; 

once have looked through list , click approved, mark date approved.

crmdatacontext x = new crmdatacontext(); list<scholarship> ss = (list<scholarship>)session["listofscholarships"]; datetime n = datetime.now;      foreach (scholarship s in ss) {         s.approved = n;            if (!x.isattached(s)) {                  x.attach(s);              }                x.updateobject(s);       }      x.savechanges(); 

this part of code

if (!x.isattached(s)) {      x.attach(s); } 

is not working correctly. gets inside if statement, checks if entity attached already, throws error

the 'scholarship' entity attached context.  

this not happen if not use session. how 1 second think entity not attached, , realize attached next? why session cause problem?

in order store entity in session, has serialized. i'm wondering if somehow messing information crm uses determine if entity in context. rather using context update, can use underlying iorgranizationalservice.

foreach (scholarship s in ss) {     // create new object in case has edited other field on object since retrieved.     // keeps updated field being overridden     service.update(new scholarship(){ id = s.id, approved = n}); } 

Comments