Note that there are some explanatory texts on larger screens.

plurals
  1. PONhibernate: Foreign key must have same number of columns as the referenced primary key
    primarykey
    data
    text
    <p>I'm confused with this situation. Having these two classes:</p> <pre><code>public class TxType { public TxType() { Payments = new List&lt;Payment&gt;(); } public string TxTypeId { get; set; } public string TxCode { get; set; } public IList&lt;Payment&gt; Payments { get; set; } public string Description { get; set; } } public class Payment { public Payment() { } public string Trn { get; set; } public TxType TxTypeId { get; set; } public string TxCode { get; set; } public System.Nullable&lt;decimal&gt; Amount { get; set; } public System.Nullable&lt;System.DateTime&gt; DateStamp { get; set; } } </code></pre> <p>TxType table have two PK (TxTypeId, TxCode), and both are FK in Payment Table. These are my mappings:</p> <pre><code> &lt;class name="TxType" table="TxType" lazy="false" &gt; &lt;composite-id&gt; &lt;key-property name="TxTypeId" column="TxTypeId" /&gt; &lt;key-property name="TxCode" column="TxCode" /&gt; &lt;/composite-id&gt; &lt;property name="Description"&gt; &lt;column name="Description" sql-type="nvarchar" not-null="false" /&gt; &lt;/property&gt; &lt;bag name="Payments" inverse="true" cascade="none"&gt; &lt;key&gt; &lt;column name="TxTypeId" /&gt; &lt;column name="TxCode" /&gt; &lt;/key&gt; &lt;one-to-many class="MyProject.Nhibernate.Repository.Payment" not-found="ignore" /&gt; &lt;/bag&gt; &lt;/class&gt; &lt;class name="Payment" table="Payment" lazy="false" &gt; &lt;id name="Trn"&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;many-to-one insert="false" update="false" lazy="false" name="TxTypeId"&gt; &lt;column name="TxTypeId" sql-type="varchar" not-null="false" /&gt; &lt;/many-to-one&gt; &lt;property name="TxTypeId"&gt; &lt;column name="TxTypeId" sql-type="varchar" not-null="false" /&gt; &lt;/property&gt; &lt;many-to-one insert="false" update="false" lazy="false" name="TxCode"&gt; &lt;column name="TxCode" sql-type="varchar" not-null="false" /&gt; &lt;/many-to-one&gt; &lt;property name="TxCode"&gt; &lt;column name="TxCode" sql-type="varchar" not-null="false" /&gt; &lt;/property&gt; &lt;property name="Amount"&gt; &lt;column name="Amount" sql-type="decimal" not-null="false" /&gt; &lt;/property&gt; &lt;property name="DateStamp"&gt; &lt;column name="DateStamp" sql-type="datetime" not-null="false" /&gt; &lt;/property&gt; &lt;/class&gt; </code></pre> <p>And I'm stuck with this error: Foreign key (FKF4FA0208CDBA724F:Payment [TxTypeId])) must have same number of columns as the referenced primary key (TxType [TxTypeId, TxCode]).</p> <p>Thanks!</p> <p>Okay, i figured out by adding these lines in Payment mapping:</p> <pre><code>&lt;many-to-one name="TxType" class="MyProject.Nhibernate.Repository.TxType" insert="false" update="false" lazy="false" &gt; &lt;column name="TxTypeId" sql-type="varchar" not-null="false" /&gt; &lt;column name="TxCode" sql-type="varchar" not-null="false" /&gt; &lt;/many-to-one&gt; </code></pre> <p>Thanks!</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