[Test]
public void Can_Get_All()
{
var repository = new RavenRepository<Motorcycle>();
repository.DeleteAll();
repository.Store(new Motorcycle {Make = "Datsun", YearManufactured = 1972});
repository.Store(new Motorcycle {Make = "Toyota", YearManufactured = 2002});
IList<Motorcycle> savedThings = repository.GetAll();
Assert.IsTrue(savedThings.Count == 2);
}
RavenRepository.GetAll()
public IList<T> GetAll()
{
using (IDocumentSession session = _collection.OpenSession())
{
return session.Query<T>().ToList(); // Throws exception
}
}
运行此测试会引发异常:
Raven.Abstractions.Exceptions.IndexCompilationException:无法理解查询:变量初始值设定项选择必须具有带有对象创建表达式的 lambda 表达式
为什么?我怎样才能从 RavenDB 中获取所有类型 T 的文档?