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
Post a Comment