Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate References Dont' save Foreign Key
    primarykey
    data
    text
    <p>I have 2 classes that reference each other. It's a weird situation that our CRM needs.</p> <p>I have an Organization and EmAddress tables and classes. The Organization inherits from Subscriber, which also has a table. I think this could be my problem, or the fact that I can't set Inverse on these because there is no "HasMany"...</p> <p>The order of insert/update is .. INSERT Email INSERT Org UPDATE Email to set Email.Subscriber</p> <p>Email.Subscriber needs to be "NOT NULL", so this doesn't work. How can I change the order, I can't use Inverse because there is no list. Just 2 references.</p> <pre><code> public class Organization : Subscriber { public override string Class { get { return "Organization"; } } EmAddress PrimaryEmailAddress {get;set;} } public class OrganizationMap : SubclassMap&lt;Organization&gt; { public OrganizationMap() { Table("Organization"); KeyColumn("Organization"); References(x =&gt; x.PrimaryEmail,"PrimaryEmailAddress").Cascade.SaveUpdate(); } } public EmAddressMap() { Id(x =&gt; x.Id, "EmAddress"); Map(x =&gt; x.EmailAddress, "eMailAddress"); References&lt;Subscriber&gt;(x =&gt; x.Subscriber,"Subscriber").LazyLoad().Fetch.Select().Not.Nullable(); /*not.nullable() throw s error. NHibernate INSERTS email, INSERTS org, UPDATES email. */ } public class EmAddress { public virtual Guid Id { get; set; } public virtual string EmailAddress { get; set; } public virtual Subscriber Subscriber { get; set; } } //Implementation var session = NHIbernateHelper.GetSession(); using(var tx = session.BeginTransaction()) { var org = new Organization(); org.PrimaryEmail = new EmAddress(){Subscriber = org}; session.Save(org); tx.commit(); </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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