- edited description
OneToMany relationship in same object
Issue #92
new
This is my example:
class A {
[PrimaryKey]
public int Id { get; set; }
public int ParentId { set; get; }
[ManyToOne(inverseProperty: "Nesteds", CascadeOperations = CascadeOperation.All)]
public A Nested { get; set; }
[OneToMany("ParentId", inverseProperty: "Nested", CascadeOperations = CascadeOperation.All)]
public List<A> Nesteds { set; get; }
[OneToMany("ParentId", inverseProperty: "AField", CascadeOperations = CascadeOperation.All)]
public List<A> AFields { set; get; }
[ManyToOne(inverseProperty: "AFields", CascadeOperations = CascadeOperation.All)]
public A AField { get; set; }
}
I want to store ParentId for both Nested and AField with one column in table A. It is always update ParentId to ParentId of AField.
Comments (4)
-
-
If they use the same foreign key, they will always be exactly the same list. You need two foreign key columns to store two different relationships.
-
reporter - edited description
-
I still see no point on doing this. How would you know if the
ParentId
refers toNested
orAFied
element at any point? - Log in to comment
Code formatting