This is a migrated thread and some comments may be shown as answers.

Telerik OpenAccess cannot fetch Master Detail result

1 Answer 53 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Youngjae
Top achievements
Rank 1
Youngjae asked on 04 May 2014, 07:18 AM
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);
08.    
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.

1 Answer, 1 is accepted

Sort by
0
Youngjae
Top achievements
Rank 1
answered on 04 May 2014, 10:50 AM
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.
Tags
LINQ (LINQ specific questions)
Asked by
Youngjae
Top achievements
Rank 1
Answers by
Youngjae
Top achievements
Rank 1
Share this question
or