This is my index code:
public class InvoiceSummaryView
{
public DateTime DueDate { get; set; }
public string CompanyAddress { get; set; }
public string DebtorName { get; set; }
public float Amount { get; set; }
public bool IsPaid { get; set; }
public string CustomerId { get; set; }
}
public class InvoiceSummaryIndex : AbstractIndexCreationTask<CustomerInvoice>
{
public InvoiceSummaryIndex()
{
Map = invoices => from invoice in invoices
select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount };
TransformResults = (database, results) =>
from invoice in results
let debtor = database.Load<Debtor>(invoice.DebtorId)
let company = database.Load<Company>(debtor.CompanyId)
select new {
DueDate = invoice.DueDate,
CompanyAddress = Company.Address.ToString(),
DebtorName = debtor.Contact.First + " " + debtor.Contact.Last,
Amount = invoice.Amount,
IsPaid = invoice.IsPaid,
CustomerId = Company.CustomerId
};
}
}
And this is my query:
var query = from viewItem in session.Query<InvoiceSummaryView>("InvoiceSummaryIndex")
where viewItem.CustomerId == id
orderby viewItem.DueDate
select viewItem;
the error is:
"Error": "System.ArgumentException: The field 'CustomerId' is not indexed, cannot query on fields that are not indexed at ...
Look at your index:
select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount };
The fields that you have indexed are DueDate, DebtorId and Amount, that is it.
If you'll it it like this:
select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount, invoice.CustomerId };
It will work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With