Pulling related data in MVC 3 from separate database

mono

New Member
Being new to MVC and the Entity Framework I've had quite a few problems performing complex data queries. I'm using a Database First approach I need to understand the best way to pull related data from a separate database. I have connected to the databases and created the edmx files as well as the models from the existing databases. I will simplify the problem example: If I have one table with employee information:\[code\]Employee_Information(EmployeeID, FullName, Address, Phone)\[/code\]Then I have a second (in another database)\[code\]Employee_Achievements(EmployeeID, Achievement, DateAchieved)\[/code\]How can I tie these two together to pull the employee's information (name, address, etc.) in a view? My initial thought was do a join and then pass that to the view:\[code\]var employee = from emp in db.EmployeeAchievementsjoin empInfo in emp_db.EmployeeInformationemp.EmployeeID == empInfo.EmployeeID\[/code\]The problem I have with this is that I'm already using a ViewModel with multiple models being passed to the view. I need the ability to tie the information in for several employees at a time with something like this in the view:\[code\]@for (int i = 0; i < model.EmployeeAchievements.Count; i++){ <tr valign="top"> <td> <div class="editor-field"> @Html.EditorFor(model => model.EmployeeAchievements.EmployeeID) @Html.ValidationMessageFor(model => model.EmployeeAchievements.EmployeeID) </div> </td>// Display employee name next\[/code\]Possible use of the ViewBag? Or is there a way that I can associate the foreign key across databases? Keep in mind this is Database First so the edmx and model files are generated. I haven't been able to find any good examples of what I'm trying to do here. I would appreciate any help and can provide more detail if needed.
 
Back
Top