Sokon1 wrote:
Otis, thanks for your answer.
If I access the Property, GetMulti_EntityName_(false) is executed. But the _alreadyFetched-Property is always TRUE when the method "GetMulti[i]EntityName[/i](bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)" later on.
Then the fetch already took place. Be aware that it is tricky to debug: if you have open a watch in the debugger which reads the collection property, it will trigger lazy loading and load the collection.
Since I now know it should be possible, here's the complete Code. Perhaps something else is wrong. (bsKapital, bsPerson1 and bsPerson2 are BindingSources)
VorgabeKapital.FetchUsingPK(3);
bsKapital.DataSource = this.VorgabeKapital;
bsPerson1.DataSource = this.VorgabeKapital.VorgabePerson[0];
bsPerson2.DataSource = this.VorgabeKapital.VorgabePerson[1];
It's a little tricky. You set VorgabeKapital as the datasource for bsKapital, which could have a DataMember set to VorgabePerson and a grid could be bound to that too. IF that's the case, at this line:
bsKapital.DataSource = this.VorgabeKapital;
the VorgabePerson collection is fetched first.
at this line:
bsPerson1.DataSource = this.VorgabeKapital.VorgabePerson[0];
VorgabePerson is fetched for the first time, if bsKapital isn't bound to a grid and datamember isn't set to VorgabePerson.
and when you access the property again on this line:
bsPerson2.DataSource = this.VorgabeKapital.VorgabePerson[1];
The collection is already fetched so the same collection is returned. If there was just 1 entity, this gives an exception.
Using this, I get the correct results:
IPrefetchPath prefetchPath = new PrefetchPath((int)Data.EntityType.VorgabePersonEntity);
prefetchPath.Add(VorgabeKapitalEntity.PrefetchPathVorgabePerson);
VorgabeKapital.FetchUsingPK(3, prefetchPath);
bsKapital.DataSource = this.VorgabeKapital;
bsPerson1.DataSource = this.VorgabeKapital.VorgabePerson[0];
bsPerson2.DataSource = this.VorgabeKapital.VorgabePerson[1];
As you fetch the data up front, lazy loading isn't triggered here at all, as the data is already fetched
This works, too:
VorgabeKapital.FetchUsingPK(3);
VorgabeKapital.GetMultiVorgabePerson(true);
bsKapital.DataSource = this.VorgabeKapital;
bsPerson1.DataSource = this.VorgabeKapital.VorgabePerson[0];
bsPerson2.DataSource = this.VorgabeKapital.VorgabePerson[1];
At this line you fetch the data:
VorgabeKapital.GetMultiVorgabePerson(true);
so any code accessing the property won't trigger lazy loading, as the data is already fetched.
But that's not lazy loading, is it? Do I have to do something to enable lazy loading? I didn't find anything in the documentation, but perhaps I simply missed it.
Lazy loading is automatic, however it of course doesn't fetch the data over and over again: if it's fetched once, it won't fetch it again. You can force it to refetch the data by passing true to the getmulti method.