首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Raven Db查询日期

Raven Db查询日期
EN

Stack Overflow用户
提问于 2013-01-18 01:09:38
回答 1查看 438关注 0票数 0

嗨,有人能回答我为什么这个linq查询不能按日期返回吗?

代码语言:javascript
复制
DocumentStore store = new DocumentStore { Url = "http://localhost:8080/" };
store.Initialize();

using (var session = store.OpenSession())
{
    bool carExists = session.Query<Car>().Any(c => c.CarId == 1);

    if (!carExists)
    {
        Car myNewCar = new Car
            {
                CarId = 1,
                ManufactureDate = new DateTime(2010, 1, 1),
                Name = "Porshe"
            };

        session.Store(myNewCar);
        session.SaveChanges();
    }

    IQueryable<Car> cars = session.Query<Car>()
            .Where(c => c.ManufactureDate == new DateTime(2010, 1, 1));

    foreach (var car in cars)
    {
        Console.WriteLine(car.Name);
    }

    Console.ReadKey();
}
EN

回答 1

Stack Overflow用户

发布于 2013-01-18 01:39:00

在第二次查询时,您的索引已失效。查看the documentation

此外,您的第一个查询应该是Load。查看the documentation

代码语言:javascript
复制
DocumentStore store = new DocumentStore { Url = "http://localhost:8080/" };
store.Initialize();

using (var session = store.OpenSession())
{
    bool carExists = session.Load<Car>(1) != null;

    if (!carExists)
    {
        Car myNewCar = new Car
            {
                CarId = 1,
                ManufactureDate = new DateTime(2010, 1, 1),
                Name = "Porshe"
            };

        session.Store(myNewCar);
        session.SaveChanges();
    }

    IQueryable<Car> cars = session.Query<Car>()
            .Customize(x=> x.WaitForNonStaleResults()) // only for testing!
            .Where(c => c.ManufactureDate == new DateTime(2010, 1, 1));

    foreach (var car in cars)
    {
        Console.WriteLine(car.Name);
    }

    Console.ReadKey();
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14384362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档