This is a migrated thread and some comments may be shown as answers.

How to retrieve only one object

5 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yang
Top achievements
Rank 1
Yang asked on 05 Jan 2012, 07:56 AM
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

5 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 05 Jan 2012, 02:10 PM
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!

0
Dmitry
Top achievements
Rank 1
answered on 21 Jun 2013, 08:44 AM
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();
0
Damyan Bogoev
Telerik team
answered on 24 Jun 2013, 02:44 PM
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.
0
Dmitry
Top achievements
Rank 1
answered on 25 Jun 2013, 05:24 AM
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).
0
Damyan Bogoev
Telerik team
answered on 27 Jun 2013, 03:46 PM
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.
Tags
General Discussions
Asked by
Yang
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Dmitry
Top achievements
Rank 1
Share this question
or