I am 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); }
It is strange that the model object has one value (as I would expect, because I know that I have one Workflow document in my database), but it has both the WorkflowId and WorkfloName properties of null . Why is this? Is there a problem with my projection?
I tried moving the call of ToArray() to to Select() , and this works 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); }
source share