You can ”return await .....ToListAsync”

> On 17 Feb 2018, at 22:31, Andrew <[email protected]> wrote:
> 
> Ok I found the problem. It's on my code. Maybe can help somebody this 
> solution.
> 
> My wrong code:
>         public async Task<List<string>> GetList()
>         {
>             using (var session = _sessionFactory.OpenSession())
>             {
>                 return session.Query<MyTable>().Where(t => t.Visible == 
> true).OrderBy(t => t.Name).Select(t => t.Name).ToListAsync()
>             }
>         }
> 
> Problem in this cose is in ToListAsync method that return Task that is not 
> yet processed, but session is closed immediately.
> 
> This is correct code:
> 
>         public async Task<List<string>> GetList()
>         {
>             using (var session = _sessionFactory.OpenSession())
>             {
>                 var result = await session.Query<MyTable>().Where(t => 
> t.Visible == true).OrderBy(t => t.Name).Select(t => t.Name).ToListAsync()
>                 return result.ToList();
>             }
>         }
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to