0

I am stuck in a weird problem. When I query data using breeze client (c#), I get data fine in my unit test. When I call the same code from my webApi controller, it hangs on task.Result. Has anyone seen this behavior? Here is the code:

// This method when called from unit test works fine, but not from webApi:

public IEnumerable<ProductBaseInformation> GetProductBaseInformation()
    {
        var result = GetAllProductBaseInformation();
        var productBase = result.Result; // GETS STUCK HERE..CODE NOT GOING FURTHER...
        return productBase;
    }  

    private async Task<IEnumerable<ProductBaseInformation>> GetAllProductBaseInformation()
            {
              _entityQuery = new EntityQuery<ProductBaseInformation>();

              var products = await _entityManager.ExecuteQuery(_entityQuery);

            return (IEnumerable<ProductBaseInformation>)products;
    }
Deepak
  • 126
  • 1
  • 11
  • consider using async/await on asynchronous operations ;) – lokusking Aug 19 '16 at 21:26
  • that's done in the details....I had not shown it earlier. Now updated that part of the code where I am doing async/await...Note it does work with unit test...returns 23,000 rows...it's doing nothing when I call GetProduceBaseInformation() method from webApi controller.... – Deepak Aug 19 '16 at 21:47
  • 1
    Looks like you're performing sync over async. Thats an AntiPattern. Make your `GetProductBaseInformation` async and `await` GetAllProductBaseInformation. Also, have a look [Here](http://stackoverflow.com/a/22629216/4558029) – lokusking Aug 19 '16 at 21:49
  • Would it be okay to post the unit test here? Because looks like you're running a query against a database somewhere and Im not sure how your unit test is returning 23000 rows. Unit tests should not have live database access to begin with but that's not the concern here. I think it would be better for you if you make GetProductBaseInformation() async :) – Swagata Prateek Aug 19 '16 at 22:06
  • Swagata Prateek: Agreed I am hitting live service which unit test should not. I am doing that because I was having no luck trying to get data from controller..hence I put the same code in unit test to see if it works. I will decouple it from service and mock it once this issue is fixed. – Deepak Aug 20 '16 at 00:30
  • lokusking: Yes, I am doing anti pattern. Here is what's happening: On session start, I intend to call this code and load data in cache. All later calls would be served by the cached data. To test if my code is returning data, I called this service from existing method in controller..just put the call in there. I am making it synchronized call so I can see the result in my debug window. Makes sense? – Deepak Aug 20 '16 at 00:32
  • Not sure if it makes any difference but the service calls breeze server for data. – Deepak Aug 20 '16 at 02:10

1 Answers1

0

lokusking..you were right. " HERE " answered my question I did Task.Run( ).Result and that did it!. Don't have the option to mark your answer as the answer so writing it here. did mark it one up..which I could thanks much everyone.

Community
  • 1
  • 1
Deepak
  • 126
  • 1
  • 11