Litedb: .ToString() in Lambda Query for Collection.Find()

Created on 23 Sep 2016  路  4Comments  路  Source: mbdavid/LiteDB

I have a collection items when i query using a lambda expression with a .ToString() it cause an exception. For example:
var y = items.Find(x => x.Year.ToString() == "1993"); // Year is int
The exception is : "Property 'Year.ToString(' was not mapped into BsonDocument"

question

All 4 comments

Hi @MoamenMohamed, there is not index functions supports. If you want create an index based on a function returns, create a field like this:

public string YearString { get { return this.Year.ToString(); } }

And than use as items.Find(x => x.YearString == "1993")

Thanks, that is exactly what i did.

Just to know, next version will support virtual function field in BsonMapper, some like this:

db.Entity<Customer>().Index("year-fn", (b) => b.Year.ToString());

So, you query will be: items.Find("year-fn", "1993")

That is great, I really love using LiteDB.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghiboz picture ghiboz  路  4Comments

dangershony picture dangershony  路  3Comments

darcome picture darcome  路  3Comments

josephinenewbie picture josephinenewbie  路  3Comments

sandolkakos picture sandolkakos  路  3Comments