Where by ID in projections

24 views
Skip to first unread message

Ivan Montilla

unread,
Aug 30, 2019, 12:35:28 AM8/30/19
to RavenDB - 2nd generation document database
Hello, I have this proyection:
return await session.Query<Post>()
    .Where(x => x.Id == "posts/1-A", false)
    .Select(x => new PostModel
    {
        Title = x.Title,
        Content = x.Content,
        PublishDate = (DateTime) x.PublishDate,
        Comments = x.Comments.Select(c =>
            new CommentModel
            {
                Author = c.AuthorName,
                Content = c.Content,
                PublishDate = c.PublishDate
            }
        )
    })
    .FirstAsync(cancellationToken);

When I do this, I expect that the generated query filter by ID of document and proyect it, so the expected query must be like this:
from Posts as x
where ID(x) = $p0
select {
    Title : x.Title,
    Content : x.Content,
    PublishDate : x.PublishDate,
    Comments : x.Comments.map(function(c){
        return {
            Author : c.AuthorName,
            Content : c.Content,
            PublishDate : c.PublishDate
        };
    })
} limit $p1, $p2

{"p0":"posts/35-A","p1":0,"p2":1}

Instead of this query, I get:

from Posts as x
where x.Id = $p0 // See this line!
select {
    Title : x.Title,
    Content : x.Content,
    PublishDate : x.PublishDate,
    Comments : x.Comments.map(function(c){
        return {
            Author : c.AuthorName,
            Content : c.Content,
            PublishDate : c.PublishDate
        };
    })
} limit $p1, $p2

{"p0":"posts/35-A","p1":0,"p2":1}

The problem is that the document doesn't have any Id property because the Id property of my Post class is mapped directly to the document ID. I think the "where" claused is not translated correctly.

Any idea how I can handle this proyection?

Arkadiusz Palinski

unread,
Aug 30, 2019, 5:17:13 AM8/30/19
to RavenDB - 2nd generation document database
Hi Ivan,

I've reported the following issue for that https://issues.hibernatingrhinos.com/issue/RavenDB-13979. It will be fixed soon.

For your purpose you can just drop the second boolean parameter of Where. So instead of

.Where(x => x.Id == "posts/1-A", false)

use

.Where(x => x.Id == "posts/1-A")


--
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/5d0c028a-2039-4016-85ea-cfab8bd69da1%40googlegroups.com.


--
Arkadiusz Paliński
Team Leader   /   Hibernating Rhinos LTD
Support:  sup...@ravendb.net
  

Ivan Montilla

unread,
Aug 30, 2019, 10:20:27 AM8/30/19
to RavenDB - 2nd generation document database
Thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages