Perhaps I generally bark for what's wrong here, but ... I have a RavenDB with a lot of objects like RavenPerson.
Each RavenPerson has a list of mail bodies, each of which has an associated date.
{
"Bodies": [
{
"RenewalRunDate": "2011-11-30T00:00:00.0000000+00:00",
"BodyText": "A bunch of text"
}
]
}
I want to take the given date and get a list of the person’s identifier and the body text associated with it.
So...
public class MailingsByDate : AbstractIndexCreationTask<RavenPerson, PersonMailingModel>
{
public MailingsByDate()
{
Map = people =>
people.SelectMany(person => person.Bodies,
(person, body) =>
new PersonMailingModel
{
MembershipNumber = person.MembershipNumber,
MailingBody = body.BodyText,
MailingDate = body.RenewalRunDate
});
}
}
but when i call it
var mailings = DocumentSession.Query<PersonMailingModel, MvcApplication.MailingsByDate>()
.Where(pmm => pmm.MailingDate == date.Value);
I get an exception
Cannot apply object of type "IntegraRenewalMailLibrary.RavenPerson" type "RenewalLogs.Models.PersonMailingModel".
Thanks in advance!
Update: Changing the index call as shown below does not eliminate the exception
var mailings = DocumentSession.Query<PersonMailingModel, MvcApplication.MailingsByDate>()
.Where(pmm => pmm.MailingDate == date.Value)
.As<PersonMailingModel>()
.ToList();
Update to update: I created a visual studio solution with sample tests here: https://github.com/pauldambra/IndexExploration
1.0.888
, , , , ...
, SelectMany linq
public class RecipientsByDate : AbstractIndexCreationTask<Person, PersonMailing>
{
public RecipientsByDate()
{
Map = people => from person in people
from body in person.Bodies
select new PersonMailing
{
MembershipNumber = person.MembershipNumber,
MailingBody = body.BodyText,
MailingDate = body.MailingDate
};
}
}