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:
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:
public partial class PropertiesDetail
{
public virtual Loan Loan { get; set; }
}
Base Repository:
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