我正在学习如何使用 LiteDB。这是我用来将 .Net 对象插入数据库的一些 C# 代码:
// Create new YacksProjectInfo object and insert it into the database
YacksProjectInfo projectInfo = new YacksProjectInfo(AssemblyName, moduleNumber);
yacksProjects.Insert(projectInfo); // Id field generated automatically
yacksProjects.EnsureIndex((YacksProjectInfo x) => x.ProjectName);
yacksProjects.EnsureIndex((YacksProjectInfo x) => x.ModuleNumber);
换句话说,每次向数据库添加新对象时,我都会使用 EnsureIndex() 方法。但我猜这不是必需的,您只需要在插入第一个对象后执行一次。
有人可以确认是否每次都需要完成 EnsureIndex(),或者一次是否足够?