0

I have started to look in to the linq provider based on The Wayward WebLog http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx.

I have this code

DbQueryProvider provider = new DbQueryProvider();
Query<Product> productQuery = new Query<Product>(provider);

IEnumerable<Product> preProductList = productQuery.Where(p => p.Id < 0).Take(4);
ICollection<Product> productList = preProductList.ToList();

I have a lot of problems finding the Take(4), witch I want to translate into Top(4) sql statement.

It seems to me, that .Take(4) is set in the expression tree only as a constant, so I have no way of knowing if it is the Take function.

Has any of you.. and idea on how to make a TakeFinder based on expression ?

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Dennis Larsen
  • 461
  • 4
  • 12

1 Answers1

0

I didn't try it, but I think you should replace your where clause for an OrderBy one. If it's ordered by ID, for example, you'll be able to take 4 of them (which will be the 4 highest or the lowest if you put an OrderByDescending instead of an OrderBy.

EDIT : I took a quick look and found another post that might be useful to you :

What's the Linq to SQL equivalent to TOP or LIMIT/OFFSET?

In case you didn't see it. ;)

Community
  • 1
  • 1
  • I have replase the where with and orderby, and that did'nt make any change. I still end up with a contant of 4, but no description of it the take-func im looking at. – Dennis Larsen Jun 22 '12 at 17:05
  • [link]http://stackoverflow.com/questions/4515550/get-all-where-calls-using-expressionvisitor[/link] in this post, the where-clause is showing op as a method call. And that kind of that I want, some way to check that THIS contant is the take() clause. – Dennis Larsen Jun 22 '12 at 17:11