是否可以在LiteDb中索引集合的属性

时间:2018-04-18 16:09:11

标签: c# .net litedb

我在litedb中有一个带有collection属性的结果对象,如下所示:

public class Result
{
    public int Id { get; set; }
    public ICollection<Entity> ExtractedEntities { get; set; }
}

public class Entity
{
    public string Value { get; set; }
    public int Id { get; set; }
}

是否可以索引实体类的属性,以便我可以执行以下操作:

collection.Find(r => r.ExtractedEntities.Any(ee => ee.Value == "test" && ee.Id == 1));

由于

1 个答案:

答案 0 :(得分:0)

是的。

using(var db = new LiteDatabase(@"C:\Temp\MyData.db"))
{
    var col = db.GetCollection<Customer>("customers");

    // Index document using document Name property
    col.EnsureIndex(x => x.Name);

    // Use LINQ to query documents
    var results = col.Find(x => x.Name.StartsWith("Jo"));

    // Let's create an index in phone numbers (using expression). It's a multikey index
    col.EnsureIndex(x => x.Phones, "$.Phones[*]"); 

    // and now we can query phones
    var r = col.FindOne(x => x.Phones.Contains("8888-5555"));
}

您可以在herehere文档中找到