How to use RIA Services QueryBuilder<T>
According to the QueryBuilder’s parameter list, an EntityQuery of T object is a candidate for query shaping. However, my attempts to do so have been unsuccessful. I’m wondering if anyone knows how to use the ApplyTo method on an EntityQuery of T in order to filter it on the client?
This is what I have so far:
The following snippet succeeds in returning all custom entities stored within a particular database table.
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var lo = ctx.Load<CustomEntity>(query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList();
};
The following snippet attempts to shape the query used above to delimit the results using the RIA Services QueryBuilder. Unfortunately, all of the data is still returned.
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var builder = new QueryBuilder<CustomEntity>();
builder.Where(c => c.Id == 1);
builder.ApplyTo(query);
var lo = ctx.Load<CustomEntity>(开发者_StackOverflow社区query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList(); --> Still returns all entities!
};
No doubt I am using the QueryBuilder incorrectly. Has anyone had any experience in applying the QueryBuilder to an EntityQuery of T?
I have realised my error. The QueryBuilder's ApplyTo method doesn't alter the orginal EntityQuery but instead returns a new one. Hence, all I needed to do was load the QueryBuilder's returned EntityQuery into the Load method of the DomainContext.
lo.Completed += (s, e) =>
{
foreach(CustomEntity item in lo.Entities)
{
list.add(item);
}
};
精彩评论