Reputation: 433
I could use some help with a RIA services query that I have been struggling with for a bit now...
Person has a collection of DailyScore.
I want to be able to produce a query that is filtered on both Person and DailyScore.
DateTime start = ...
DateTime end = ...
var personQuery = context.GetPersonQuery().Skip.(10).Take(10)
var scoresQuery = from s in ctx.GetDailyScoresForPeriod(start, end)
where personQuery.Contains(s.Person)
select s;
...load the scoresQuery
What I would ideally want is the Person objects loaded with the appropriate DailyScores for the specified period.n We can assume all the 'includes' are in place too.
Is this possible in RIA Services? If so, can somebody give me the correct way of going about it, and if not are there any work arounds?
I feel like this is a simple request, so hopefully this is easy.
Thanks is advance, Shane.
Also, can someone point me to a good online resource about the rules around using EntityQueries on the client side with RIA Services? I have struggled to find anything like this.
Upvotes: 1
Views: 412
Reputation: 18530
Actually, the query you are trying to do is not supported. You can't use Contains
, Any
, and similar constructs where you need to filter data in a collection.
In these scenarios you have two options:
Perform both queries separately, and then filter the data on the client. This approach has performance issues, because you are retrieving all the data from the server, and then filtering it out. In your case, you would something like this:
var personQuery = context.GetPersonQuery().Skip.(10).Take(10);
var scoresQuery = context.GetDailyScoresForPeriodQuery(start, end);
// Load both queries and then:
scores.Where(s => persons.Contains(s.Person))
Perform the query in the server. This approach is more performant, but you need to define a way to filter the persons in the same query. In your case, if you only want the persons whose ids fall in a specific range for example, you should add this method to your domain context (in the server):
IQueryable<DailyScore> GetDailyScoresForPeriodForPersons(DateTime start, DateTime end, int firstPerson, int lastPerson)
{
return context
.DailyScores
.Where(s => s.Start > start && s.End < end)
.Where(s => s.Person.ID >= firstPerson && s.Person.ID < lastPerson)
}
Then in your client, you would call it like this:
var scoresQuery = context.GetDailyScoresForPeriodForPersons(start, end, 10, 20)
Some resources:
Upvotes: 3