D
D
ddidi2014-05-06 09:59:58
C++ / C#
ddidi, 2014-05-06 09:59:58

Entity framework relationship parrent children in same table

table
ID
doc_number
parrent_doc_number
I didn't make the table, I can't change it to refer to id. how to connect them in the model?
so that you can access them
public virtual Payment ParentPayment { get; set; }
public virtual ICollection ChildPayments { get; set; }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoliy Mikhailov, 2014-10-13
@ddidi

What if you try like this?

public class Payment 
    {
            [Key]
           public int doc_number{ get; set; }
    
     public int? parrent_doc_number{ get; set; }
     public virtual Payment parrent { get; set; }
или
 public virtual Payment parrent_ { get; set; }
           public virtual ICollection ChildPayments { get; set; } 
    }

As I remember, EF first looks for the navigation property based on the type name and
if it does not find a match, it looks at the field name and again pk
in both cases it connects the navigation property name and the pk name either together or through an underscore .. .

D
ddidi, 2015-07-01
@ddidi

The whole point is that I wanted to connect not by PK. I did not make the base, it was already like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question