c# - Entity Framework 6 Async DBContext Access with Enums -


i'm utilizing ef 6's ability utilize enum's properties in entity object.

when try querying datasource asynchronously using enum property part of criteria, query never returns. however, if make query synchronously completes successfully. sql generated ef identical both cases, , correct.

here simplified version of entity object:

public class rolegroup {     public int id { get; set; }      [column("requestsubtypeid")]     public subtypeenum? subtypeid { get; set; } } 

here's simplified version of enum:

public enum subtypeenum {     accountspayableinquiry = 1,     payrollinquiry = 2,     billinginquiry = 3 } 

here's method i'm using retrieve role group database, based on subtypeid parameter:

public async task<rolegroup> getrolegroupbysubtype(subtypeenum subtypeid) {     return await context.workflowrolegroups                         .firstasync(rolegroup => rolegroup.subtypeid == subtypeid); } 

using context.database.log = s => debug.writeline(s); i'm able see following sql produced above method:

select top (1)      [extent1].[id] [id],      [extent1].[requestsubtypeid] [requestsubtypeid]  [dbo].[workflowrolegroups] [extent1] [extent1].[requestsubtypeid] = @p__linq__0  -- p__linq__0: '1' (type = int32, isnullable = false) 

however, that's far execution gets. nothing happens, no errors thrown. in output window see "the thread has exited code 0".

when make method synchronous, below example, correct results returned database , well. sql query generated identical async one.

public rolegroup getrolegroupbysubtype(subtypeenum subtypeid) {     return context.workflowrolegroups                   .first(rolegroup => rolegroup.subtypeid == subtypeid); } 

i'd appreciate guidance in understanding why using async in enum part of criteria causes issue.

it has nothing ef use of async/await , mixing task.result (which cause deadlock) in call stack. entire call stack should use async/await @ every point (also called async way). without seeing other code in call stack there no way know part causing deadlock.

here source understanding why/how deadlock can occur don't block on async code. stephen cleary (author of referenced article) commonly responds async-await questions on so.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -