c# - Forcing EF ApplicationUser To Load Navigation Properties -


i using ef6/.net 4.5.1 retrieve data listview in usercontrol on webform. have modified applicationuser include navigation property [1:1] using fk attribute has been working great.

public class applicationuser : identityuser {     public applicationuser()     {         createdate = datetime.now;         :\\ deleted stuff     }      public int taxid { get; set; }     public system.guid applicationid { get; set; }     :\\ deleted stuff      [foreignkey("taxid")]     public virtual personnel personnel { get; set; } } 

the model migrated , tested storing , retrieving.

everything works fine full postback.

however added button on webpage opens , closes div holds usercontrol responsible creating new member. usercontrol throws event consumed container. container closes div containing uc, reopens div listview, calls listview databind() calls getallusers().

the code:

public iqueryable<applicationuser> getallusers() {     var manager = httpcontext.current.getowincontext()                              .getusermanager<applicationusermanager>();     var users = manager.users.orderby(c => c.taxid);      return users; } 

a problem arises after usercontrol returns control container.

the first retrieve - has applicationuser not have navigation property loaded. means fields never populated in listview.

subsequent retrieves (a refresh of page or calling edit of row) however, seem trigger navigation properties present.

image showing first , second retrieve

  1. how can force ef include navigational property. syntax manager.users.include() not exist in context.

  2. only entities listed dynamicproxies of applicationuser seems have navigational property present. i'm mystified why initial retrieve never dynamicproxy.

  3. the listview's datapager requires iqueryable implement paging. not call .tolist() datapager knows when has been working great ... once there full page refresh. why page refresh required navigational properties materialize?

any ... in advance ...

add

using system.data.entity; 

and can use include:

var users = manager.users.include(x=> x.personnel).orderby(c => c.taxid); 

if want include navigation anywhere, in identityconfig.cs file override applicationusermanager.users this:

public class applicationusermanager : usermanager<applicationuser> {     public override iqueryable<applicationuser> users     {                 {             return base.users.include(x=>x.personnel);//include want here         }     }     //rest of original code } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -