entity framework - Not able to access list of record in EF -


here problem trying access records data base based on 1 field . field using audit_id having type guid .

but line not returning data

var audits = ctx.audits.where(x => lstaudits.contains(x.audit_id)).tolist(); 

here full code update mass records in database using ef

//will select auditid list         var lstaudits = _viewmodel.workinglistaudits.where(x => x.workinglist).select(x=>x.auditid).tolist();                     using (var ctx = new auditentities())         {             var audits = ctx.audits.where(x => lstaudits.contains(x.audit_id)).tolist();             audits.foreach(x => x.working_list = false);             ctx.savechanges();         } 

in case of single record return data database

  var lstaudits = _viewmodel.workinglistaudits.where(x => x.workinglist).select(x => x.auditid).tolist();         guid tempauditid = lstaudits[0];         // lstaudits.foreach(x => x.tostring().toupper());         using (var ctx = new auditentities())         {             var audits = (from au in ctx.audits                           au.audit_id == tempauditid                           select au).tolist();             //foreach(audit audit in   audits){              //}             audits[0].working_list = false;             ctx.savechanges();         } 

finally got answer here updated code working fine .i took intermediate result in temporary variable , started working expected

  //will select auditid list            var lstaudits = _viewmodel.workinglistaudits.where(x => x.workinglist).select(x => x.auditid).tolist();         using (var ctx = new auditentities())         {             var tempaudits = ctx.audits.tolist();             var audits = tempaudits.where(x => lstaudits.contains(x.audit_id)).tolist();             audits.foreach(x => x.working_list = false);             ctx.savechanges();         } 


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -