Telerik OpenAccess cannot fetch Master Detail result

Thread is closed for posting
2 posts, 0 answers
  1. Youngjae
    Youngjae avatar
    5 posts
    Member since:
    Jul 2012

    Posted 04 May 2014 Link to this post

    I'm new to Telerik OpenAccess. 
    I create Database-first approach with rlinq file and auto-generated classes. There are Master and Detail tables, which Master can have no Detail ID (DetailId column in Master can be NULL). pretty banal.

    I want to get 5 records of Master-Detail hierarchical data through Json in ASP.NET MVC WebApi, so I write following code but it returns NullReferenceException.   

    01.public IQueryable<Master> GetNoticeQuestions(string category)
    02.  {
    03.   var fetchStrategy = new Telerik.OpenAccess.FetchOptimization.FetchStrategy();
    04.   fetchStrategy.LoadWith<Master>(c => c.Detail);   IQueryable<Master> entity = repository.GetAll().LoadWith(fetchStrategy)
    05.    .Where(m => m.DetailId != null && m.DetailId.Value == m.Detail.Id)
    06.    .OrderByDescending(m => m.GenerateTime)
    07.    .Take(5);
    09.   return entity;
    10.  }

    I have two questions. 
    1. What am I wrong in above code?
    2. I see `GetAll()` method perform `SELECT ... FROM Table` SQL query in order to fetch all records firstly, and then perform a query from them in program memory (checked by Telerik Data Access Profiler). is it right? Telerik autogenerated repository pattern file only expose GetAll and GetBy method (for single entity), so I try to use it.

    The Telerik documentation is dataContext based only, so it is hard to do with new auto-generated repository pattern.

  2. Youngjae
    Youngjae avatar
    5 posts
    Member since:
    Jul 2012

    Posted 04 May 2014 in reply to Youngjae Link to this post

    I found adequate solution.
    Download Telerik Data Access sample file, install it, and open "ASP.NET Web API with Kendo UI" Visual Studio Solution.
    It has RentalOrderRepository.Partial.cs file guide me all about my question.
Back to Top