Can @Last-Modified be used in a Where directly (without going through an index)?

289 views
Skip to first unread message

jbu...@gmail.com

unread,
Jan 4, 2021, 1:41:00 PM1/4/21
to RavenDB - 2nd generation document database
This code doesn't work, but I hope demonstrates what I am trying to do. (The error is "Cannot understand how to translate value". I understand why it's happening. Is there another way to do this though?)

             session.Query<ProfileMovedCatalogsEvent>()
                 .Where(r => r.Tenant == machine.Tenant)
                 .Where(r => session.Advanced.GetLastModifiedFor(r) > changeId)


The only solutions I have been able to find are to go through an Index. Which I can do, just was hoping there would be a more direct way.

Thanks,
Josh

jbu...@gmail.com

unread,
Jan 5, 2021, 10:23:13 AM1/5/21
to RavenDB - 2nd generation document database
I'm using Raven 4.2.108 by the way.

Igal Merhavia

unread,
Jan 6, 2021, 2:35:42 AM1/6/21
to rav...@googlegroups.com
Hi, 
In your example, you compared a last modified time with Id?
If you want to query base on metadata in general and particular on a last modified time you can do it as follow:
[Fact]
public async Task Test()
{
    using var store = GetDocumentStore();

    var user1 = new User();
    var user2 = new User();
    DateTime time;
    using (var session = store.OpenAsyncSession())
    {
        await session.StoreAsync(user1);
        await session.SaveChangesAsync();

        await Task.Delay(1000);
        time = DateTime.UtcNow;
        await Task.Delay(1000);

        await session.StoreAsync(user2);
        await session.SaveChangesAsync();
    }

    using (var session = store.OpenAsyncSession())
    {
        var results = await session.Advanced
            .AsyncRawQuery<User>("from Users as u where u.'@metadata'.'@last-modified' > $time")
            .AddParameter("time", time)
            .ToArrayAsync();

        var results2 = await session.Advanced.AsyncDocumentQuery<User>()
            .WhereGreaterThan("@metadata.@last-modified", time)
            .ToArrayAsync();

        Assert.True(results.Length == 1 && results[0].Id == user2.Id);
        Assert.True(results2.Length == 1 && results2[0].Id == user2.Id);
    }
}
If your scenario is different please submit a failing test?  https://ravendb.net/docs/article-page/4.2/csharp/start/test-driver 

Best regards,
Igal

Igal Merhavia
Developer   /   Hibernating Rhinos LTD
Support:  sup...@ravendb.net
  


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/dfd85063-487a-44fe-8fd4-5457cd73e972n%40googlegroups.com.

Josh Buedel

unread,
Jan 6, 2021, 11:12:50 AM1/6/21
to rav...@googlegroups.com
The session.Advanced.DocumentQuery api is exactly what I am looking for. Thanks!

(changeId from my example is a poorly named variable. It is of type DateTime.)

You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/R71sUi4HHNg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/CAADcGSmbvUO3jLMjhA-s7mmEb1%2BLf4S7QFhP0JOc%3D6q2aLbeWw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages