I have a brown-field application with 5 domain objects: CreditMemo,
CreditMemoDetail, SalesInvoice, ReceivablesRecord, TransactionType.
CreditMemo is one--many with CreditMemoDetail. It is also many-to-one with
SalesInvoice. SalesInvoice is one-to-many with ReceivablesRecord which is
many to one with TransactionType (xml mapping below). None of the
relationships depend upon any values outside of their direct parent/child.
When I perform a Get<CreditMemo>(id), I get the entire structure back
correctly: The columns from CreditMemo are properly filled out, the
ISet<CreditMemoDetail> is correct, and the entire
SalesInvoice/ReceivablesRecord/TransactionType hierarchy is fully
populated. When I perform a Get<SalesInvoice>(invoiceNumber), the
SalesInvoice object is filled correctly but the ISet<ReceivablesRecord> is
empty. Using NHProfiler, the exact same queries are executed, including the
parameters. I've been knocking this one around for hours now and haven't
been able to come up with anything that makes sense.
I know that I can brute force things but the fact that the relationships
work automagically when starting with a CreditMemo but not when starting
with a SalesInvoice is driving me nuts. Any ideas?
Objects and Mappings:
public class CreditMemo
{
public virtual int CreditMemoId { get; set; }
public virtual string CreditMemoNumber { get; set; }
public virtual DateTime CreditDate { get; set; }
public virtual string InvoiceNumber { get; set; }
public virtual string ReturnToStock { get; set; }
public virtual string Posted { get; set; }
public virtual string Notes { get; set; }
public virtual Iesi.Collections.Generic.ISet<CreditMemoDetail>
Details { get; set; }
public virtual SalesInvoice InvoiceInfo { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
schema="aladdin" namespace="Receivables.Models">
<class name="Receivables.Models.CreditMemo, Receivables" lazy="false"
table="credit_memo">
<id name="CreditMemoId" column="credit_memo_id">
<generator class="identity" />
</id>
<property name="InvoiceNumber" column="invoice_no" />
<property name="CreditMemoNumber" column="credit_memo_no" />
<property name="CreditDate" column="credit_date" type="DateTime" />
<property name="ReturnToStock" column="return_to_stock" />
<property name="Posted" column="posted" />
<property name="Notes" column="notes" />
<many-to-one name="InvoiceInfo" class="SalesInvoice"
column="invoice_no" update="false" insert="false" />
<set name="Details" cascade="delete">
<key column="credit_memo_id" />
<one-to-many class="CreditMemoDetail"/>
</set>
</class>
</hibernate-mapping>
public class CreditMemoDetail
{
public virtual int CreditMemoDetailId { get; set; }
public virtual int CreditMemoId { get; set; }
public virtual string CreditType { get; set; }
public virtual decimal Amount { get; set; }
public virtual string AffectCommission { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
schema="aladdin" namespace="Receivables.Models">
<class name="Receivables.Models.CreditMemoDetail, Receivables"
lazy="false" table="cr_memo_detail">
<id name="CreditMemoDetailId" column="crmemodetailid">
<generator class="identity" />
</id>
<property name="CreditMemoId" column="credit_memo_id" />
<property name="CreditType" column="credit_type" />
<property name="Amount" column="amount" />
<property name="AffectCommission" column="affect_commission" />
</class>
</hibernate-mapping>
public class SalesInvoice
{
public virtual string InvoiceNumber { get; set; }
public virtual string Customer { get; set; }
public virtual DateTime InvoiceDate { get; set; }
public virtual string SalesPerson { get; set; }
public virtual string ClassOfSale { get; set; }
public virtual Iesi.Collections.Generic.ISet<ReceivablesRecord>
Transactions { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
schema="aladdin" namespace="Receivables.Models">
<class name="Receivables.Models.SalesInvoice, Receivables" lazy="false"
table="invoice">
<id name="InvoiceNumber" column="invoice_no">
<generator class="assigned" />
</id>
<property name="Customer" column="customer" />
<property name="InvoiceDate" column="invoice_date" type="DateTime" />
<property name="SalesPerson" column="salesman" />
<property name="ClassOfSale" column="class" />
<set name="Transactions">
<key column="invoice_no" />
<one-to-many class="ReceivablesRecord"/>
</set>
</class>
</hibernate-mapping>
public class ReceivablesRecord
{
public virtual string InvoiceNumber { get; set; }
public virtual DateTime AccrecDate { get; set; }
public virtual string TxType { get; set; }
public virtual decimal Amount { get; set; }
public virtual string Note { get; set; }
public virtual TransactionType TypeInfo { get; set; }
public override bool Equals(object obj)
{
bool result = false;
try
{
ReceivablesRecord input = (ReceivablesRecord)obj;
if (InvoiceNumber == input.InvoiceNumber && AccrecDate ==
input.AccrecDate && TxType == input.TxType)
{
result = true;
}
}
catch (Exception ex)
{
}
return result;
}
public override int GetHashCode()
{
return string.Format("{0}{1}{2}", InvoiceNumber, AccrecDate,
TxType).GetHashCode();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
schema="aladdin" namespace="Receivables.Models">
<class name="Receivables.Models.ReceivablesRecord, Receivables"
lazy="false" table="accrec">
<composite-id>
<key-property name="InvoiceNumber" column="invoice_no" />
<key-property name="AccrecDate" column="accrec_date" type="DateTime"
/>
<key-property name="TxType" column="tx_type" />
</composite-id>
<property name="Amount" column="amount" />
<property name="Note" column="note" />
<many-to-one name="TypeInfo" class="TransactionType" column="tx_type" />
</class>
</hibernate-mapping>
public class TransactionType
{
public virtual string TransactionCode { get; set; }
public virtual string Description { get; set; }
public virtual decimal GLAccountNumber { get; set; }
public virtual string Taxable { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
schema="aladdin" namespace="Receivables.Models">
<class name="Receivables.Models.TransactionType, Receivables"
lazy="false" table="txtype">
<id name="TransactionCode" column="tx_code">
<generator class="assigned" />
</id>
<property name="Description" column="description" />
<property name="GLAccountNumber" column="gl_account_no" type="Decimal"
/>
<property name="Taxable" column="taxable" />
</class>
</hibernate-mapping>
Repository Code:
public CreditMemo GetById(int id)
{
return NhSession.Get<CreditMemo>(id);
}
public SalesInvoice GetInvoiceByInvoiceNumber(string id)
{
SalesInvoice salesInvoice = NhSession.Get<SalesInvoice>(id);
return salesInvoice;
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/7M90FFNAJNEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.