OneToMany relationship in same object

Issue #92 new
Minh Dinh created an issue

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)

  1. Guillermo Gutiérrez

    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.

  2. Guillermo Gutiérrez

    I still see no point on doing this. How would you know if the ParentId refers to Nested or AFied element at any point?

  3. Log in to comment