@Walaa, that would not have the safety stop of the max limit the method will ever return (so whatever the user specifies, the method will never return N rows, e.g. 500). WIth a public service I can imagine one doesn't want to rely on clients to do 'the right thing', if a wrong query could bring the server down because it fetches all rows.
@arash, I've been thinking about this, and I have to clarify a bit:
if a Take() call is specified on a sequence in a Linq query which in itself is seen as a separate query (so not merged with an outer query/sequence), the inner Take is kept as-is, as it should. However multiple Take() calls on effectively the same query are not: the most outer Take call will overwrite the inner one: in the simplest situation (sequence.Take(n).Take(m)), it will simply overwrite the value on the handled 'sequence' expression for the # of elements to fetch, in the situation where you have sequence.Take(n).SomeOtherMethod().SomeOtherMethod2()....Take(m), and everything can be merged together into 1 query (e.g. linqMetaData.Customer.Take(n).OrderBy(..).Take(m)), we also don't keep the inner query, but merge them all together for efficiency reasons, but this will also overwrite the inner one with the outer one.
In both situations it's rather silly to do so, we concluded, because linqMetaData.Customer.Take(10).Take(20), will never result in 20 rows because the set to select 20 on has at most 10 rows. The same is true for: linqMetaData.Customer.Take(20).Take(10), it will never result in 20 rows, as the Take(10) will make sure at most 10 rows will returned.
This means that if a value for MaxNumberOfElementsToReturn is already set to a value, and it is about to be overwritten with value V, it only should do so if V is smaller than the existing value (and >=0) otherwise it should ignore the value.
This is rather easy to add, problem is: it's a breaking change: if we make this change, it will be changing resultsets for queries which rely on this. So we'll add a setting for this (static) which is undocumented for now, which will be present in v3.5, 4.0 and further, and which will by default result in the current behavior, but when switched off, it will be the behavior you need: When multiple Take calls are present in the same query, the smaller value wins.
In v4.1 (currently in development) we'll reverse this setting's default value, meaning we'll introduce the breaking change but people who want to keep the old behavior can do so by using the (then documented) switch. We'll make this change because we concluded it's a bug in our code: the behavior our code currently has is silly, and therefore we introduce this change back in v3.5.
I'll post in this thread again with an updated v3.5 runtime and how to use it so you'll get the queries you need.