Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
public class EntityDataProvider : DbContext, IDataProviderEntity
{
    public EntityDataProvider(string connectionStringName, bool enableLazyLoading = true)
            : base(connectionStringName)
        {
            Configuration.LazyLoadingEnabled = enableLazyLoading;
        }
}

POCO object Account:
public class Account
{
    ...
        private ICollection<CodeSegment> _codeSegments;
         public virtual ICollection<CodeSegment> CodeSegments
        {
            get
            {
                return _codeSegments ?? (_codeSegments = new Collection<CodeSegment>());
            }
            protected set
            {
                _codeSegments = value;
            }
        }
}

With the code above I get these results, which is what I expect
CodeSegmets.Count = 4

When I change the following:
Configuration.LazyLoadingEnabled = true;
public ICollection<CodeSegment> CodeSegments (removed virtual)


Results:
CodeSegments.Count = 0

Change:
Configuration.LazyLoadingEnabled = false;
public virtual ICollection<CodeSegment> CodeSegments (added virtual)

Results:
CodeSegments.Count = 0

Configuration.LazyLoadingEnabled = false;
public ICollection<CodeSegment> CodeSegments (removed virtual)


Results:
CodeSegments.Count = 0

Can anyone shed some light on this?
Posted

1 solution

Without virtual you definitely don't have lazy loading.
The second example would lazy load, if you did not have the configuration disabled that feature. So there is no need for confusion here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900