When I run the code
1 |
List<Product> products = documentSession.Query<Product>().Where(p => p.ProductSn.Contains(barCode)).ToList(); |
I got following exception
RavenDB NotSupportedException
An exception of type 'System.NotSupportedException' occurred in Raven.Client.Lightweight.dll but was not handled in user code
Additional information: Could not understand expression: .Where(p => p.ProductSn.Contains(value(YSPOS.MainWindow+<>c__DisplayClass10_0).barCode))
It's because there is no index for ProductSn attribute is created.
Solution
To fix this issue, we need create index fo ProductSn attribute.
Create a class extending AbstractIndexCreationTask class
1 2 3 4 5 6 7 8 9 10 11 |
public class ProductsByProductSn:AbstractIndexCreationTask<Product> { public ProductsByProductSn() { Map = products => from product in products select new { ProductSn = product.ProductSn }; } } |
Then execute this index creation task after DocumentStore initialization.
1 2 3 4 5 6 7 8 |
private EmbeddableDocumentStore _dataStore; _dataStore = new EmbeddableDocumentStore { DataDirectory = "Data" }; _dataStore.Initialize(); new ProductsByProductSn().Execute(_dataStore); |