New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It has an endless loop, and its ideal result is the same as "Teacher=null", because I have no Include. #29364
Comments
My expression may not be very good. The problem I want to say is that it is infinitely nested. |
I don't know how to solve this problem. I hope I can get help. Thank you. |
internal class Student_TeacherConfig : IEntityTypeConfiguration<Student_Teacher>
{
public void Configure(EntityTypeBuilder<Student_Teacher> builder)
{
builder.ToTable("T_Student_Teacher");
////复合主键
builder.HasKey(b => new { b.StudentId, b.TeacherId });
builder.Property(m => m.IsBind).HasDefaultValue(0);
}
} internal class StudentConfig : IEntityTypeConfiguration<Student>
{
public void Configure(EntityTypeBuilder<Student> builder)
{
builder.ToTable("T_Student");
builder.HasMany(m => m.Student_Teachers)
.WithOne(m => m.Student)
.HasForeignKey(m => m.StudentId);
}
} internal class TeacherConfig : IEntityTypeConfiguration<Teacher>
{
public void Configure(EntityTypeBuilder<Teacher> builder)
{
builder.ToTable("T_Teacher");
builder.HasMany(m => m.Student_Teachers)
.WithOne(m => m.Teacher)
.HasForeignKey(m => m.TeacherId);
}
} |
I have something similar to this. Seems to be a problem with include function |
In my opinion, many historical questions are similar to this problem. It seems that there is no good solution. There is self reference. If the referenced object is still its own object, the result will be extended indefinitely. |
@panjonsen See #11564. Make sure to read the full discussion to really understand what is going on. |
@ajcvickers I have seen this problem, but it seems that there is no effective solution. For example, you can set it not to be fixed by infinite loops through features or code. As a result, people need to do a lot of extra things to make up for him. At present, I also use select to repair, but I think this is just a forced method. It should not be the solution he really should have. |
@ajcvickers I hope that the solution proposed with previous developers will be more effective and useful. To set it so that it will not continue to be repaired. |
@panjonsen Your questions are answered in the comments on #11564. |
services.AddDbContext(options => This is the best solution I think, but it will also bring some additional work, such as the update needs additional processing. |
It has an endless loop, and its ideal result is the same as "Teacher=null", because I have no Include.
Include provider and version information
EF Core version:6.0.9
Database provider: Pomelo.EntityFrameworkCore.MySql
Target framework:NET 6.0
Operating system:
IDE: 2022
The text was updated successfully, but these errors were encountered: