Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a query on performance related issue in code fist migration.
I am using Entity Framework Code first in my application. For parent child relationship I have created some public virtual ICollection<ClassType> PropertyName { get; set; }
And also I have initialized each property on the Parent Class Constructor.
And for accessing the parent class I have creating object of parent class which also initialized the child entity.
When I am trying to access the parent class from Data Base, all the child entity also loaded with the parent entity as a dynamic entity. And also the child entity contains Parent entity and so on.

Is it Create a Performance issue when i Load the Entity?

Please check the Below code

Parent Entity:
C#
public partial class Loan : BaseEntity<Loan>
{  
    #region Constructors

    public Loan()
    {
        this.LoansPropDetails = new List<PropDetail>();
        this.IRates = new List<IRate>();
        this.LoanContactCompanies = new List<ContactCompany>();
        this.Documents = new List<Document>();
        this.Extensions = new List<Extension>();
        this.Figures = new List<Figure>();
        this.LoansItems = new List<LoansItem>();
        this.Confirmations = new List<Confirmation>();
        this.Activities = new List<Activity>();
        this.Audits = new List<Audit>();
        this.Alerts = new List<Alert>();
    }

    #endregion Constructors

    public virtual ICollection<Document> Documents { get; set; }
………………
………………
}


Child Entity:
C#
public partial class PropertiesDetail
{
    // other Property declaration
    public virtual Loan Loan { get; set; }
}


Base Repository:
C#
protected BaseRepository(bool proxyEnabled = true)
{
    try
    {
        if (this._dataContext == null)
        {
            this._dataContext = new LoneContext();
        }

        this._dataContext.Configuration.AutoDetectChangesEnabled = true;
        this._dataContext.Configuration.ProxyCreationEnabled = proxyEnabled;
        this._dbSet = _dataContext.Set<T>();
    }
    catch (Exception exs)
    {
        
    }
}


All the repository class are inherited from the Base repository and if I make the proxyEnabled= true, then I am getting Parent entity as well as the child entity data as dynamic data and if I make it false then I am only getting the parent entity, others entity counts come as 0.
I want to improve the performance, which way I can implement the code to improve the performance.

Any help is really appreciated.
Thank you
Pradeep
Posted
Updated 9-Sep-14 4:26am
v5
Comments
George Jonsson 9-Sep-14 2:47am    
What is the bottleneck in your solution now?
pk.pradeep 9-Sep-14 10:25am    
I want to know which way i can design the solution , so that the performance will increases.
Nathan Minier 9-Sep-14 12:37pm    
Without knowing what your BaseEntity looks like it's hard to say. I do suspect that you have more initialization occurring than you need to, as EF will do quite a bit of work behind the curtain.

Looking at your POCO here, though, I suspect that you need to define your relations a bit better. All those lists of (I assume) complex items will not translate well, it's better if they're each setup as an individual models and mapped appropriately, using virtual ICollections to provide your linkages.

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