Featured post
c# - Fluent NHibernate and friend relationship -
i need model friend relationship fluent nhibernate. company model has list<company> related related companies. relations between companies modeled in database in table, related looks this:
customer_id | related_id
both columns foreign key pk in customers table.
the problem relations saved once each pair (do call bi-directional?).
i'm able change table structure if it's easier solve in way.
i need map fluent nhibernate when customer.related(), generates query like:
select * companies left join related on customer_id = id or related_id = id   i've tried map in number of different ways, closest i've tried is:
hasmanytomany(x => x.related)        .inverse()        .parentkeycolumn("customer_id")        .childkeycolumn("related_id")        .table("relations")        .cascade.all();   however, (of course) maps when customer_id matches.
how solve this?
edit: think it's similar fluent nhibernate: how create one-to-many bidirectional mapping?, not me much.
i think want achieve half way done. you've mapped 2 entities many2many relation already. wouldn't touch mapping further.
instead query want thru mapping. this.
function getrelated(long id){     return session.query<related>()                  .where(r=>r.customer.id == id || r.related.id == id)                  .tolist();  }   a reccomendation tho, mapped entity's name related , have related field might sound confusing, i'd suggest rename else (if possible).
hope helps.
- Get link
 - X
 - Other Apps
 
Comments
Post a Comment