entity framework - PostgreSql EF, navigation property is always null when querying -


i stumbled upon unexpected behaviour when using entity framework postgresql.

when query context navigation property inside clause, null , fails. if add there include method pointing navigational propery it's working

this work

context.garages.include("postalcode").where(f=>f.postalcode.regionid == regionid) 

this not (postalcode null , fails on nullreference)

context.garages.where(f=>f.postalcode.regionid == regionid) 

i don't think had add query when using mssql. can anybdoy explain me.

if want navigation properties lazy loaded, need declare them virtual:

public garage {  //...  public virtual postalcode postalcode {get;set;}  } 

in link find conditions must follow entities if want enable lazy loading entities , have entity framework track changes in classes changes occur.

if navigation property virtual, other option think cause behavior if turn off lazy loading on context:

public class yourcontext : dbcontext  {     public yourcontext()     {       this.configuration.lazyloadingenabled = false;     }  } 

if call include method, going load related entity part of query. load behavior called eager loading. on other hand, if use lazy loading, related entity going loaded first time accessed, behavior looking for.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -