This problem occurs in the processing of hierarchical queries. Based on previous experience, when querying the subset B [] of A and A, join the score to Two Queries quickly, however, when there are many sub-sets and so on, the time is not linear growth but an index, because the efficiency load caused by repeated data increases. For example, the first type of unit test time is about 4-6, when we add three child sets, we will be in the range of 14-22, while the practice in Ef is to set up unicon for each join result. It is strange to look at the large string of data without being slow, but we should be separated.
Time
Test code:
Public class ModelTesting
{
Private EFContext _ dbContext;
Public ModelTesting ()
{
String cnn = System. Configuration. ConfigurationManager. ConnectionStrings [0]. ConnectionString;
_ DbContext = new EFContext (cnn );
}
[Fact]
Public void Test ()
{
Var key = 1000;
Var uid = new Guid ("3905858E-A32E-DF11-BA8F-001CF0CD104B ");
Var myResume = _ dbContext. Set <MyUser> ()
. Single (u => u. UserId = uid );
MyResume. Works. ToList ();
MyResume. Resumes. ToList ();
MyResume. Projects. ToList ();
MyResume. Jobs. ToList ();
MyResume = _ dbContext. Set <MyUser> ()
. Include ("Resumes ")
. Include ("Jobs ")
. Include ("Projects ")
. Include ("Works ")
. Single (u => u. UserId = uid );
}
}
Public class EFContext: DbContext
{
Public EFContext (string cnn): base (cnn)
{
This. Configuration. LazyLoadingEnabled = true;
}
Protected override void OnModelCreating (DbModelBuilder modelBuilder)
{
Base. OnModelCreating (modelBuilder );
ModelBuilder. Entity <MyResume> ();
ModelBuilder. Entity <MyWorkExper> ();
ModelBuilder. Entity <MyProject> ();
ModelBuilder. Entity <MyUser> ();
}
}
[Table ("Resume", Schema = "dbo")]
Public class MyResume
{
[Key]
Public int Key {get; set ;}
[ForeignKey ("Owner")]
Public Guid UserId {get; set ;}
Public MyUser Owner {get; set ;}
}
[Table ("WorkExperience", Schema = "Resume")]
Public class MyWorkExper
{
[Key]
Public int WorkId {get; set ;}
[ForeignKey ("Owner")]
Public Guid UserId {get; set ;}
Public MyUser Owner {get; set ;}
}
[Table ("project", Schema = "Resume")]
Public class MyProject
{
[Key]
Public int ProjectId {get; set ;}
[ForeignKey ("Owner")]
Public Guid UserId {get; set ;}
Public MyUser Owner {get; set ;}
}
[Table ("EnterpriseUser", Schema = "Offer")]
Public class MyUser
{
[Key]
[Column ("UserGuid")]
Public Guid UserId {get; set ;}
Public virtual ICollection <MyResume> Resumes {get; set ;}
Public virtual ICollection <MyProject> Projects {get; set ;}
Public virtual ICollection <MyWorkExper> Works {get; set ;}
Public virtual ICollection <MyJob> Jobs {get; set ;}
}
[Table ("Offer", Schema = "Offer")]
Public class MyJob
{
[Key]
Public long Key
{
Get;
Set;
}
[ForeignKey ("Owner")]
[Required]
Public Guid UserID {get; set ;}
Public virtual MyUser Owner {get; set ;}
}