Note that there are some explanatory texts on larger screens.

plurals
  1. POHow is a Fluent Nhibernate Reference / HasMany relationship supposed to work?
    primarykey
    data
    text
    <p>I have two tables setup with a reference and hasmany relationship. When the Xref.SaveOrUpdate() is called an "Invalid index 7 for this SqlParameterCollection with Count=7." exception is thrown. I get the feeling I'm not setting up the HasMany and References correctly. What should I be doing differently?</p> <pre><code>public class PortalPhysicianMap : ClassMap&lt;PortalPhysician&gt; { public PortalPhysicianMap() { Table("PortalPhysicians"); Id(x =&gt; x.PhysicianRno).GeneratedBy.Identity(); Map(x =&gt; x.A1PhysicianRno); Map(x =&gt; x.LastName); Map(x =&gt; x.FirstName); Map(x =&gt; x.TitleName); Map(x =&gt; x.SuffixName); Map(x =&gt; x.CorrName); Map(x =&gt; x.Specialty); Map(x =&gt; x.Institution); Map(x =&gt; x.Addr1); Map(x =&gt; x.Addr2); Map(x =&gt; x.City); Map(x =&gt; x.State); Map(x =&gt; x.PostalCode); Map(x =&gt; x.Country); Map(x =&gt; x.Phone); Map(x =&gt; x.Fax); Map(x =&gt; x.InactiveDt); Map(x =&gt; x.CreatedDate, "CreatedDt"); Map(x =&gt; x.UpdatedDate, "UpdatedDt"); HasMany(x =&gt; x.Xrefs) .KeyColumn("A1PhysicianRno"); //.Cascade.All(); } } public class PortalLoginPhyXrefMap : ClassMap&lt;PortalLoginPhyXref&gt; { public PortalLoginPhyXrefMap() { Table("PortalLoginPhyXref"); Id(x =&gt; x.XrefRno).GeneratedBy.Identity(); Map(x =&gt; x.LoginRno); Map(x =&gt; x.A1PhysicianRno); Map(x =&gt; x.UserName); Map(x =&gt; x.UserRole); Map(x =&gt; x.InactiveDt); Map(x =&gt; x.CreatedDate, "CreatedDt"); Map(x =&gt; x.UpdatedDate, "UpdatedDt"); References&lt;PortalPhysician&gt;(x =&gt; x.Login) .Column("LoginRno"); } } using (ISession s = Env.dbPortal.OpenSession()) { try { using (ITransaction Trans = s.BeginTransaction()) { Trans.Begin(); foreach (PortalLogin Login in lstLogins) { if (Login.UserName != null) { Login.SaveOrUpdate(s); foreach (PortalLoginPhyXref Xref in Login.Xrefs) { Xref.LoginRno = Login.LoginRno; Xref.SaveOrUpdate(s); } } } Trans.Commit(); } } catch (Exception Ex) { frmError.Show(Ex); } } </code></pre> <p>Additional code showing what happens in the SaveOrUpdate()</p> <pre><code>public class PortalLoginPhyXref : BaseRec { public virtual void SaveOrUpdate(ISession Sess) { base.SaveOrUpdate(Sess, XrefRno); } } public abstract class BaseRec { public virtual DateTime CreatedDate { get; set; } public virtual string CreatedUserID { get; set; } public virtual DateTime? UpdatedDate { get; set; } public virtual string UpdatedUserID { get; set; } public virtual void SaveOrUpdate(ISession Sess, int Rno) { SaveOrUpdate(Sess, (Rno == 0)); } public virtual void SaveOrUpdate(ISession Sess, string ID) { SaveOrUpdate(Sess, (ID == null)); } private void SaveOrUpdate(ISession Sess, bool Save) { if (Save) { CreatedDate = DateTime.Now; CreatedUserID = Env.UserID; } UpdatedDate = DateTime.Now; UpdatedUserID = Env.UserID; Sess.SaveOrUpdate(this); } } </code></pre>
    singulars
    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