This question is locked. New answers and comments are not allowed.
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.
I have two questions.
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.
- What am I wrong in above code?
- 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.