c# - Accessing an Eager loaded navigation property causes lazy load -


i have navigation property eager loaded inside using statement. now, in view when try access property non-existent fk(f.e. -1 or deleted row in master table), ef tries lazy load , fails, since context disposed. there can prevent exception? first option catching it, other turn off lazy loading , maybe proxy creation in same occasion...but there other options or checks preformed?

public actionresult details(int id) {     post post;     using (var db = new blogdbcontext())     {         post = db.posts.where(p => p.id == id)             .include(p => p.comments.select(c => c.author))             .singleordefault();     }     if (post == null)     {         return httpnotfound();     }      return partialview(post); } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -