Get FirstOrDefault using Async method

3,402 views
Skip to first unread message

Nguyen Phuong

unread,
Mar 31, 2013, 6:54:13 AM3/31/13
to rav...@googlegroups.com
Hi All
I design model User:
public class User
{
public string Id{ get; set; }
public string PublicGuid{ get; set; }
public string UserName{ get; set; }
...
}
 
In this model: Id = PublicGuid: define 1 user
I declared:  public IAsyncDocumentSession docAsyncSession { get; set; }
And , this is my code to get user by publicguid
    var user = (await docAsyncSession.Query<Project.Document.Model.User>()
                                             .Where(u => u.PublicGuid== publicguid)
                                             .ToListAsync())
                                             .FirstOrDefault();

How to get FirstOrDefault in async method,  that not need get list first
Thanks all advance

Kijana Woodard

unread,
Mar 31, 2013, 10:59:31 AM3/31/13
to rav...@googlegroups.com

ToList or ToListAsync is going to pull the entire list.

I thought there was some pull request activity around async versions of various linq extensions.

You could make a pr for FirstOrDefaultAsync or try .Take(1).ToListAsync().

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nguyen Phuong

unread,
Mar 31, 2013, 10:25:58 PM3/31/13
to rav...@googlegroups.com
Tks Kijana Woodard for support. :D


2013/3/31 Kijana Woodard <kijana....@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "ravendb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/Jy2_vwwvx6Y/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.

Fitzchak Yitzchaki

unread,
Apr 2, 2013, 6:39:07 AM4/2/13
to <ravendb@googlegroups.com>
We have FirstOrDefaultAsync support in 2.5.

Kijana Woodard

unread,
Apr 2, 2013, 9:23:28 AM4/2/13
to rav...@googlegroups.com

Thanks for that. I was still checking ayende/ravendb master.

Reply all
Reply to author
Forward
0 new messages