Why am I getting this error in a RavenDB index request: the "CustomerId" field is not indexed

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 request:

 var query = from viewItem in session.Query<InvoiceSummaryView>("InvoiceSummaryIndex") where viewItem.CustomerId == id orderby viewItem.DueDate select viewItem; 

error:

"Error": "System.ArgumentException: the field" CustomerId "is not indexed, cannot request fields that are not indexed ...

+4
source share
1 answer

Look at your index:

  select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount }; 

The fields you indexed are DueDate, DebtorId, and Amount, i.e.

If you like it:

  select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount, invoice.CustomerId }; 

He will work

+8
source

Source: https://habr.com/ru/post/1394865/


All Articles