I'm doing a project for my college with entity framework where I need to get multiple data from tables without references to each other. The idea would be that in a list basic information appears and when you click the "details" button it shows all the information including those that are not related to this table.
I tried to do this in the controller but sadly, with no success:
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
ProcessArea processArea = db.ProcessArea.Find(id);
if (processArea == null)
{
return HttpNotFound();
}
var query = from ap in db.ProcessArea
join mg in db.GenericGoal on ap.IdProcessArea equals mg.IdGenericGoal
select new ProcessAreaModelView()
{
InitialsLevelMaturity = mg.Initials,
NameLevelMaturity = mg.Name,
DescriptionLevelMaturity = mg.Description,
Initials = ap.Initials,
Name = ap.Name,
Description = ap.Description
};
query.ToList();
return View(query);
}
I have a model called "Process Area" and as I had to do join I believe I have to have another model since they are different information so I created the "ProcessAreaModelView"
When I click on "details" an error appears:
The template item inserted in the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery'1 [AkaelApp.Models.AreaProcessoModelView]', but this dictionary requires an item of type 'AkaelApp.Models.AreaProcessoModelView'.
What I doing wrong?