我在ASP.NET MVC中使用Raven如下:
[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);
}
奇怪的是model
对象中有一个值(正如我所期望的那样,因为我知道我的数据库中有一个Workflow
文档),但WorkflowId
和WorkfloName
上的null
属性为ToArray()
。为什么是这样?我的预测有问题吗?
我已尝试将Select()
调用调用之前的[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);
}
,这样就可以了:
{{1}}
答案 0 :(得分:1)
如果您将视图模型中属性的名称更改为与Workflow类相同,则它将起作用。
model = session.Query<Workflow>()
.Select(w => new WorkflowIndexViewModel { Id = w.Id, Name = w.Name })
.ToArray();
但这只是一个似乎是错误或限制的解决方法。