Question regarding .Take(NumItems)

10 posts, 0 answers
  1. Seabus
    Seabus avatar
    33 posts
    Member since:
    Jun 2011

    Posted 13 Sep 2011 Link to this post


    Hi,

    Simple question:

    var query = (from Person p in Persons select p).Take(5).ToList();

    Does OpenAccess turn this into a SELECT TOP 5 statement ??? :-)


    MadSeb


  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 14 Sep 2011 Link to this post

    Hello Seabus,

    Simple answer: Yes.

    All the best,
    Thomas
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
  4. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 09 Feb 2012 Link to this post

    Hello, if I have something like this:

    var c = from p in ctx.GetAll<Person >().Where(x => x.Name.Contains(e.Text)).Take(15)
                               select new
                                      {
                                          p.IdPerson,
                                          p.name
                  };

    var count = c.Count(); //<- this will not be 15, it will be the total where clause result count

    What am I doing wrong?
  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 09 Feb 2012 Link to this post

    Hello Rui,

    I just double checked that this does not occur. Which database version and which OpenAccess version do you use? Do you use fetchplans or FetchStrategy ? Can you give us your .rlinq file?
    Greetings,
    Thomas
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 09 Feb 2012 Link to this post

    Hello,
    telerik openaccess version: 2011.3.1129.2
    DB Version: SQLServer 2008 R2

    I just build the rlinq from the DB and the I just use something like:

     using (var ctx = new DbContext())
                {

    var c = from p in ctx.GetAll<Person >().Where(x => x.Name.Contains(e.Text)).Take(15)
                               select new
                                      {
                                          p.IdPerson,
                                          p.name
                  };

    var count = c.Count();

    }
  7. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 09 Feb 2012 Link to this post

    I'm using .NET 3.5, does it matter?
  8. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 09 Feb 2012 Link to this post

    Hello.
    The database is taken from http://northwind.codeplex.com/
    In attachement is a sample application (with rlinq file: http://www.wupload.com/file/2661526527/WebApplication1.7z

    thank you
  9. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 10 Feb 2012 Link to this post

    Hello Rui,

    works like a charm on my side...

    SELECT TOP(@__TAKE) a.[ContactName] AS COL1, a.[ID] AS COL2 FROM [Customer] a


    Please double check your configuration, esp. that there is no reference to older OpenAccess versions.
    I tested here with the newest upcoming build.

    Greetings,
    Thomas
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  10. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 11 Feb 2012 Link to this post

    I don't quite understand how you get that query...
    What version are you using?
    Since it's a Count() why in you query there is no TOP?

    here is my result for count(): untitled.png

    when I use tolist: tolist.png

  11. Rui
    Rui avatar
    30 posts
    Member since:
    Feb 2012

    Posted 11 Feb 2012 Link to this post

    With the Latest internal build: 2011.3.1320.1 is working.
Back to Top
DevCraft banner