I am using Entity Framework 5.0 for my MVC4 project. There is a problem with that. When I give a db model for any view, the dispatcher sends the model without relation
Example
I have a user class and relationship departments
when i use it in the controller
using(context) { var user = context.Find(id); string department = user.Department.Name; }
works when called in context. but when i do it
using(context) { var user = context.Find(id); return View(user); }
and call it like
Model.Department.Name
I got an error.
Here is my answer, but its bad
using(context) { var user = context.Find(id); string department = user.Department.Name; return View(user); }
when I try to use Model.Department.Name in the view, I did not get an error, I have to do this for each relationship when I use the class as a model. is there a better solution to this problem? I want to use all the relationships in the view without invoking them in the controller.
I hope you can understand me, sorry, my English.
source share