Note that there are some explanatory texts on larger screens.

plurals
  1. POReverse.KeyColumn("[...]") in Fluent NHibernate
    text
    copied!<p>The key point is that the KeyColumn is at the BASE table. You can see that there is a one-to-many relationship between User and Follow from the following code.</p> <pre><code>public class Activity { public virtual User Executor { get; set; } //probably I should set some kind of Polymorphism here? } public class Follow : Activity { public virtual User Followee { get; set; } } public class User { public virtual IList&lt;Follow&gt; Follows { get; set; } } </code></pre> <p>so I mapped them as the following:</p> <pre><code>public class ActivityMap : EntityMap&lt;Activity&gt; { public ActivityMap() { References&lt;User&gt;(m =&gt; m.Executor); } } public class FollowMap : SubclassMap&lt;Follow&gt; { public FollowMap() { References(m =&gt; m.Followee); } } public class UserMap : EntityMap&lt;User&gt; { public UserMap() { HasMany(m =&gt; m.Follows) .Inverse(); //.KeyColumn("Executor_id"); } } </code></pre> <p>Please notice the KeyColumn() map. "Executor_id" is not in table tb_Follow but in table tb_Activity(for subclass strategy). If code like the above, a new column "Executor_id" will be generated in tb_Follow, which I think duplicated.</p> <p>Now how can I refer to the "Executor_id" column in tb_Activity?</p> <p>PS: the table structure.</p> <pre><code>tb_Follow +-------------+-------------+---------+ + Activity_id + Followee_id + User_id + +-------------+-------------+---------+ + 1 + 7 + NULL + +-------------+-------------+---------+ tb_Activity +-------------+-------------+---------+ + id + Executor_id + Type + +-------------+-------------+---------+ + 1 + 6 + Follow + +-------------+-------------+---------+ </code></pre> <p>so it's User(6) -- follow --> User(7)</p> <p>the User_id should be 6 in my resolution, the same(and I think duplicated) with Executor_id</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload