c# - Entity Framework. Cannot retrieve data -
i met strange behavior , don't have idea may related to. tried retrieve data 2 ways: pure linq , stored procedure data not coming back. no errors or exceptions. on sql server side can see profiler stored procedure executed.
public async task<ienumerable<ordersdto>> getall(int userid) { ordersdto[] result; try { sqlparameter param = new sqlparameter("@userid", userid); result = await _db.database.sqlquery<ordersdto>("userorders @userid", param).toarrayasync(); //var result = await _db.order.where(x=> x.customerid == 1) // .include(x => x.orderdetails) // .include(x => x.orderstatus) // .include(x => x.paymentstatus) // .asnotracking().toarrayasync(); } catch (exception ex) { throw new exception(ex.message); } return result; }
when await
reached, thread returned caller. when checking await
result, because you're not waiting completion of task not getting result. if run query synchronously can see desired result:
result = _db.database.sqlquery<ordersdto>("userorders @userid", param).toarray();
there no problem run code asynchronously, should check result when task completed:
Comments
Post a Comment