I’m looking for the best approach to my problem.
I need to display the names only of 3 different entities, not the rest of the information.
Entities are:
db.TR{TRID, ProjectID, TemplateID, version}
db.Project{ProjectID, ProjectName}
db.Template{TemplateID, TemplateName}
I would like the best approach to display all the results in a grid like this:
TRID - ProjectName - TemplateName - Version
I would like to know how you would do the Model, Controller(Index Function) and the view.
So far, my View function looks like this:
public ViewResult Index()
{
var viewModel = from tr in db.TRs
join proj in db.Projects on tr.ProjectID equals proj.ProjectID
join templ in db.Templates on tr.TemplateID equals templ.TemplateID
orderby proj.ProjectName
select new
{
TRList = tr.TRID,
TemplateList = templ.TemplateName,
ProjectList = proj.ProjectName,
Version = tr.version
}
return View(viewModel); //Go in Index.cshtml
}
And the View is:
@model IEnumerable <OnlineTR.WebUI.Areas.Admin.Models.TRManagerModel>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelitem => item.TRList);
</td>
<td>
@Html.DisplayFor(modelitem => item.ProjectList);
</td>
<td>
@Html.DisplayFor(modelitem => item.TemplateList);
</td>
</tr>
}
I’m trying to find a way to use a sql request that only use what I need.
If you can show me how to use the .include, it would be awesome. So far I have try, but it doesn’t accept lambda expressions in the (), it wants a string path. (maybe missing a using?)
Thanks a lot. Alex.
The problem with your code is that you are passing IEnumerable of anonymous type to your view, but it expects the type
Fix your LINQ query to select a concrete type, and it will work