c# - EF + AutoFac | Navigation properties are not getting reloaded/refreshed -


following code:

entity.invoice instoreinvoice = invoicerepository.find(x => x.accountid == accountid && x.companyid == companyid && x.id == invoicenum); if (instoreinvoice.customermaster.someid == null) {     // external code updates customermaster someid value.     // .....      // .....     // want reload instoreinvoice updated value of customermaster.someid     instoreinvoice = invoicerepository.find(x => x.accountid == accountid && x.companyid == companyid && x.id == invoicenum); } string value = instoreinvoice.customermaster.someid; // gives me null..!! 

code seems self-explanatory (let me know if need me elaborate on point). invoicerepository.find() internally calls dbset.firstordefault() .. i.e. first entity list matches query expression. customermaster navigation property invoice entity

my question is, why statement,

string value = instoreinvoice.customermaster.someid; // gives me null..!! 

gives null value?! tried below options did not work, same result (entity instoreinvoice object passing).

1. context.entry(entity).state = entitystate.detached; 2. context.entry(entity).reload(); 3. ((iobjectcontextadapter)context).objectcontext.detach(entity); 4. ((iobjectcontextadapter)context).objectcontext.refresh(refreshmode.storewins, entity); 

thoughts?

thanks!


Comments