I'm using Raven in ASP.NET MVC as follows:
[HttpGet]
public ActionResult Index()
{
ViewBag.Title = Strings.Workflows;
ViewBag.AddNewText = Strings.Add_new;
IEnumerable<WorkflowIndexViewModel> model;
using (var session = DocumentStore.OpenSession())
{
model = session.Query<Workflow>()
.Select(w => new WorkflowIndexViewModel { WorkflowId = w.Id, WorkflowName = w.Name })
.ToArray();
}
return View(model);
}
The weird thing is that the model
object has one value in (as I'd expect because I know I have oneWorkflow
document in my database), but both WorkflowId
and WorkfloName
properties on it arenull
. Why is this? Is there a problem with my projection?
I have tried moving the ToArray()
call to before the Select()
, and that works just fine:
[HttpGet]
public ActionResult Index()
{
ViewBag.Title = Strings.Workflows;
ViewBag.AddNewText = Strings.Add_new;
IEnumerable<WorkflowIndexViewModel> model;
using (var session = DocumentStore.OpenSession())
{
model = session.Query<Workflow>()
.ToArray()
.Select(w => new WorkflowIndexViewModel { WorkflowId = w.Id, WorkflowName = w.Name });
}
return View(model);
}