I have 2 classes like with the following structure, Person has 2 many-one relations with SchoolClass:
public class Person
{
public int Id { get; set; }
public List<SchoolClass> SchoolClasses { get; set; }
public List<SchoolClass> OldSchoolClasses { get; set; }
}
public class SchoolClass
{
public int Id { get; set; }
public string Name { get; set; }
}
I can add ghostProps but can't change the classes.
When I make a migration for EFCore, it adds 2 different Person Id's to the SchoolClass table which I want to avoid.
I want to generate 2 many to many tables instead:
Is this possible with Fluent API?
Perhaps you should try inheritance:
public class SchoolClass // this could be abstract
{
public int Id { get; set; }
public string Name { get; set; }
}
public class NewSchoolClass : SchoolClass
{
}
public class OldSchoolClass : SchoolClass
{
}
public class Person
{
public int Id { get; set; }
public IList<NewSchoolClass> NewSchoolClasses { get; set; }
public IList<OldSchoolClass> OldSchoolClasses { get; set; }
}
And in DbContext:
-DbSet<SchoolClass> SchoolClasses { get; set; }
+DbSet<OldSchoolClass> OldSchoolClasses { get; set; }
+DbSet<NewSchoolClass> NewSchoolClasses { get; set; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.