How to retrieve only one object

6 posts, 0 answers
  1. Yang
    Yang avatar
    1 posts
    Member since:
    Jan 2012

    Posted 05 Jan 2012 Link to this post

    Hi
     I'm trying to retrieve only current object ,not including children objects:

                FetchStrategy fetchStrategy = new FetchStrategy();
                fetchStrategy.MaxFetchDepth = 1;
                fetchStrategy.MaxResultsLimit = 1;
                dbContext.FetchStrategy = fetchStrategy ;

                IEnumerable<Sample> samples = dbContext.Sample.Where(s => s.SampleBarcode == sampleBarcode);

    but result includes many children object,such as Sample.SampleItem ...

    Tell what should I do .

    Thanks
    Dgyang
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 05 Jan 2012 Link to this post

    Hello Yang,

    Initially only the current object is being retrieved. If you try to access some of the navigation members of this object, additional calls to the database will be made in order to retrieve the necessary information for them. This means that the navigation members are loaded on-demand.
    Hope that helps.

    Kind regards,
    Damyan Bogoev
    the Telerik team

    Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. DevCraft banner
  4. Dmitry
    Dmitry avatar
    8 posts
    Member since:
    Oct 2012

    Posted 21 Jun 2013 Link to this post

    When executing the following code, the query sent to database doesn't contain TOP 1 statement. But MaxResultsLimit = 1. Why?

    var ctx = new FluentModel();
    ctx.FetchStrategy = new FetchStrategy {MaxResultsLimit = 1, MaxFetchDepth = 1};
    ctx.FetchStrategy.LoadWith((Group t) => t.Users);
     
    var result = ctx.Groups.ToList();
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 24 Jun 2013 Link to this post

    Hello Dmitry,

    You need to use the Take Linq Extension method in order to achieve that goal.

    Hope that helps.

    Regards,
    Damyan Bogoev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  6. Dmitry
    Dmitry avatar
    8 posts
    Member since:
    Oct 2012

    Posted 25 Jun 2013 Link to this post

    Sorry for misunderstanding. I mean that MaxResultsLimit doesn't affect Group.Users property.
    I want to limit that number of fetching linked records for each container record, because a fetch may be large (1 million users for each group).
  7. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 27 Jun 2013 Link to this post

    Hello Dmitry,

    I am afraid the MaxResultsLimit setting is not respected during the Linq query processing, but only for OQL one.

    You need to use the Take / Limit Linq extension methods to achieve this goal.

    Regards,
    Damyan Bogoev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top
DevCraft banner