views:

74

answers:

1

I have a database which will eventually contain thousands of records and will search this list using the Silverlight autocompletebox control and WCF RIA services. I am using the base implementation without any parameters for the "GetXXXQuery" in my domain datasource:

public IQuerable<XXX> GetXXXs()
{
    return this.ObjectContext.XXXs;
}

I will be using the return value of this query in an autocomplete using the "Name" as the ValueMemberPath.

My list of objects is quite small now, so it is very fast to list all the records I have. My question is: Once my list of records becomes larger, or if more people hit the server, is this implementation efficient? Is it returning the entire list of records in my database, or is the IQueryable object somehow allowing for a query based upon the string in my autocomplete box, effectively returning a small subset of records from my database?

Thanks, Dennis

A: 

If you add a search term to a RIA Linq query, i.e. add a where clause to the RIA Linq query, it will be resolved server-side. Only the matching results will be passed back, not the whole table*.

IQuerable<> queries are actually serialized on the client by Ria services and passed to the the server to execute. Brilliant system. Especially useful for paging/searching millions of records.

*(Note: If you get a lots of matches for a given term you may need to decide whether to return a limited number of records. You also do not want to start a search unless at least 3 characters have been typed in).

Enough already
HiTech Magic - thanks for the reply, but your mention of the datagrid and paging makes me wonder... In that scenario, isn't the query manipulated after-the-fact by the pager such that it calls skip(n).take(m) on the returned IQueryable<XXX>? The query in the domaindatasource itself doesn't require a page #/page size parameter, right? I guess I could try looking at this with fiddler to see the response... That may clarify it for me, but I thought I'd ask anyway.
Dennis Ward
You mentioned the where clause... that is what I thought the autocomplete control took care of, after all, it has modes such as "starts with" or "contains", with and without case sensitivity, all of which would need to be replicated by my "GetXXX" query which doesn't make sense to me.
Dennis Ward
@Dennis Ward: Quite right. I get carried away typing without reading it back sometimes. You can indeed put the additional clauses on client side. It is the evaluation of the query that causes the sending of the Linq to the server. I will go correct my wording on the answer :)
Enough already
HiTech Magic - thanks again. I've been looking into this a bit more and found that I should take your suggestion, and use the "OnPopulating" event and pass e.Parameter (the PopulatingEventArgs e that is passed in the OnPopulating event). I guess I'm looking for a confirmation or more concrete answer... Any suggestions?
Dennis Ward