Re: [nhusers] Re: Sql Server async problem?

2018-02-19 Thread Andrew
You're right. Thanks

Il giorno domenica 18 febbraio 2018 14:04:06 UTC+1, Gunnar Liljas ha 
scritto:
>
> You can ”return await .ToListAsync”
>
> On 17 Feb 2018, at 22:31, Andrew  wrote:
>
> Ok I found the problem. It's on my code. Maybe can help somebody this 
> solution.
>
> My wrong code:
> public async Task GetList()
> {
> using (var session = _sessionFactory.OpenSession())
> {
> return session.Query().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 GetList()
> {
> using (var session = _sessionFactory.OpenSession())
> {
> var result = await session.Query().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 nhusers+u...@googlegroups.com .
> To post to this group, send email to nhu...@googlegroups.com 
> .
> 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 nhusers+unsubscr...@googlegroups.com.
To post to this group, send email to nhusers@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.


Re: [nhusers] Re: Sql Server async problem?

2018-02-18 Thread Gunnar Liljas
You can ”return await .ToListAsync”

> On 17 Feb 2018, at 22:31, Andrew  wrote:
> 
> Ok I found the problem. It's on my code. Maybe can help somebody this 
> solution.
> 
> My wrong code:
> public async Task GetList()
> {
> using (var session = _sessionFactory.OpenSession())
> {
> return session.Query().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 GetList()
> {
> using (var session = _sessionFactory.OpenSession())
> {
> var result = await session.Query().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 nhusers+unsubscr...@googlegroups.com.
> To post to this group, send email to nhusers@googlegroups.com.
> 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 nhusers+unsubscr...@googlegroups.com.
To post to this group, send email to nhusers@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.