Free relationship NHibernate and friend

I need to model friends with Fluent NHibernate. My company model has List<Company> Relatedwith related companies. Relations between the companies are modeled in my database in a table relatedthat looks like this:

customer_id | related_id

Both columns are the foreign key for PK in my table customers.

The problem is that the relationship is saved only once for each pair (do you call it bidirectional?).

I can change the structure of the table if it is easier to solve in another way.

I need to display Fluent NHibernate so that when I customer.Related()generate a query like:

SELECT * FROM companies LEFT JOIN related ON customer_id = id OR related_id = id

I tried to display this in different ways, the closest I tried:

HasManyToMany(x => x.Related)
       .Inverse()
       .ParentKeyColumn("customer_id")
       .ChildKeyColumn("related_id")
       .Table("relations")
       .Cascade.All();

, () , customer_id.

?

: , Fluent NHibernate: " " ?, .

+3
1

, . 2 Many2Many. .

, , . - .

function GetRelated(long id){

   return Session.Query<Related>()
                 .Where(r=>r.Customer.Id == id || r.Related.Id == id)
                 .ToList(); 
}

tho, - , , , - ( ).

, .

0

Source: https://habr.com/ru/post/1781394/


All Articles