RavenDB: devolver objetos con valores nulos para propiedades

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);
}

Lo raro es que el model object has one value in (as I'd expect because I know I have one Workflow document in my database), but both WorkflowId y WorkfloName properties on it are null. Why is this? Is there a problem with my projection?

He intentado mover el ToArray() llamar a antes de los 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);
}

preguntado el 08 de noviembre de 11 a las 16:11

When you run the query (the one not working) what does the raw http request look like? -

1 Respuestas

If you change the names of your properties in the view model to the same as the Workflow class it will work.

model = session.Query<Workflow>()
        .Select(w => new WorkflowIndexViewModel { Id = w.Id, Name = w.Name })
        .ToArray();

But that is just a workaround to what seems to be a bug or a limitation.

respondido 09 nov., 11:00

Fixed in unstable. But you already know that groups.google.com/group/ravendb/browse_thread/thread/… ;) - asgerhallas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.