Does that idea?
2014-06-17 14:00 GMT+03:00 Atilla İlhan KARTAL <[email protected]> : > Sorry; > > public virtual void Calculate(CalculationMethod method) > { > if (DocumentType.Equals(DocumentType.PosProceedsVoucher)) > { > if (Pos!=null) > { > Cash = Pos.Partner; > } > } > > if (method.Equals(CalculationMethod.Currency)) > { > LocalAmount = Amount*ExchangeRate; > AccountAmount = LocalAmount/AccountExchangeRate; > > } > else if (method.Equals(CalculationMethod.LocalCurrency)) > { > Amount = LocalAmount / ExchangeRate; > AccountAmount = LocalAmount/AccountExchangeRate; > } > else if (method.Equals(CalculationMethod.AccountCurrency)) > { > LocalAmount = AccountAmount * AccountExchangeRate; > Amount = LocalAmount / ExchangeRate; > } > > if (DocumentType.Equals(DocumentType.CreditCardPaymentVoucher)) > { > Transactions.Clear(); > if (CreditCard!=null) > { > Cash = CreditCard.Partner; > } > var installmentAmount = Amount / Installment; > var installmentDate = PaymentDate; > for (int i = 0; i < Installment; i++) > { > PartnerTransaction receivableTransaction = new > PartnerTransaction(); > receivableTransaction.Partner = Cash; > receivableTransaction.Receivable = installmentAmount; > receivableTransaction.LocalReceivable = > installmentAmount * ExchangeRate; > receivableTransaction.Currency = Currency; > receivableTransaction.LocalCurrency = LocalCurrency; > //receivableTransaction.Payment = this; > receivableTransaction.TransactionDateTime = > PaymentDate; > receivableTransaction.ExchangeRate = ExchangeRate; > receivableTransaction.Expiry = installmentDate; > Transactions.Add(receivableTransaction); > installmentDate = installmentDate.AddMonths(1); > } > > PartnerTransaction debtTransaction = new > PartnerTransaction(); > debtTransaction.Partner = Partner; > debtTransaction.Debt = AccountAmount; > debtTransaction.LocalDebt = LocalAmount; > debtTransaction.Currency = AccountCurrency; > debtTransaction.LocalCurrency = LocalCurrency; > //debtTransaction.Payment = this; > debtTransaction.TransactionDateTime = PaymentDate; > debtTransaction.ExchangeRate = ExchangeRate; > debtTransaction.Expiry = DateTime.Today; > Transactions.Add(debtTransaction); > } > Save(); > } > > > public virtual M Save() > { > bool isCurrentActivatedTransaction = false; > try > { > > OnBeforeSave(); > if (!Session.Transaction.IsActive) > { > BeginTransaction(); > isCurrentActivatedTransaction = true; > } > try > { > Session.SaveOrUpdate(this); > } > catch (NonUniqueObjectException) > { > Session.Merge(this); > } > > if (isCurrentActivatedTransaction) > { > Commit(); > } > try > { > Session.Refresh(this); > } > catch (Exception) > { > } > OnAfterSave(); > } > catch (Exception) > { > if (isCurrentActivatedTransaction) > { > Rollback(); > } > throw; > } > return (M)Convert.ChangeType(this, typeof(M)); > } > > > 2014-06-17 13:51 GMT+03:00 Ricardo Peres <[email protected]>: > > What code are you using? >> >> RP >> >> >> On Tuesday, June 17, 2014 10:53:36 AM UTC+1, Atilla İlhan KARTAL wrote: >>> >>> Dear All; >>> >>> When i recreate a collection in Payment Entity saveOrUpdate method >>> throwed this exception. My Releation Mappings is AllDeleteOrphan but i dont >>> resolve this problem. >>> >>> I am working on this error two days ago. I'm going crazy :'( >>> >>> I tested this solution method. >>> >>> 1- Manual handle cascade operation. >>> a-Delete exists PartnerTransactions on before save >>> b-Save Payment entity >>> c- Save new PartnerTransactions >>> >>> but throw object references an unsaved transient instance - save the >>> transient instance before merge. >>> >>> What do you think about it.? >>> >>> object references an unsaved transient instance - save the transient >>> instance before flushing or set cascade action for the property to >>> something that would make it autosave. Type: >>> Core.PartnerManagement.PartnerTransaction, >>> Entity: Core.PartnerManagement.PartnerTransaction >>> >>> >>> public class PaymentMap : ClassMap<Payment> >>> { >>> public PaymentMap() >>> { >>> Table("SALES_TB_PAYMENT"); >>> SchemaAction.None(); >>> Id(x => x.ID, "ID").GeneratedBy.Identity(); >>> Map(x => x.PaymentDate, "PaymentDate"); >>> Map(x => x.Serial, "Serial"); >>> Map(x => x.DocumentNumber, "DocumentNumber"); >>> References(x => x.Partner, "PartnerId"); >>> References(x => x.Cash, "CashId"); >>> References(x => x.Pos, "PosId"); >>> References(x => x.DocumentType, "DocumentTypeId"); >>> Map(x => x.Description, "Description"); >>> >>> Map(x => x.ExchangeRate, "ExchangeRate"); >>> Map(x => x.AccountExchangeRate, "AccountExchangeRate"); >>> Map(x => x.Amount, "Amount"); >>> Map(x => x.AccountAmount, "AccountAmount"); >>> Map(x => x.LocalAmount, "LocalAmount"); >>> Map(x => x.BankSEQ, "BankSEQ"); >>> References(x => x.Bank, "BankId"); >>> Map(x => x.IBAN, "IBAN"); >>> Map(x => x.AccountNo, "AccountNo"); >>> Map(x => x.BankBranch, "BankBranch"); >>> Map(x => x.ReferenceNo, "ReferenceNo"); >>> Map(x => x.SlipNo, "SlipNo"); >>> Map(x => x.RewardAmount, "RewardAmount"); >>> Map(x => x.ComissionRate, "ComissionRate"); >>> Map(x => x.ComissionAmount, "ComissionAmount"); >>> Map(x => x.LocalComissionAmount, "LocalComissionAmount"); >>> Map(x => x.Installment, "Installment"); >>> >>> References(x => x.Currency, "CurrencyId"); >>> References(x => x.LocalCurrency, "LocalCurrencyId"); >>> References(x => x.AccountCurrency, "AccountCurrencyId"); >>> References(x => x.CreditCard, "CreditCardId"); >>> HasMany(x => x.Transactions) >>> .KeyColumn("PaymentId") >>> .Cascade.AllDeleteOrphan() >>> .AsBag(); >>> } >>> } >>> >>> >>> public class PartnerTransactionMap : ClassMap<PartnerTransaction> >>> { >>> public PartnerTransactionMap() >>> { >>> Table("CORE_TB_PARTNERTRANSACTION"); >>> SchemaAction.None(); >>> Id(x => x.ID, "ID").GeneratedBy.Identity(). >>> UnsavedValue(0L); >>> Map(x => x.TransactionDateTime, "TransactionDateTime"); >>> References(x => x.Partner, "PartnerId"); >>> References(x => x.Currency, "CurrencyId"); >>> References(x => x.LocalCurrency, "LocalCurrencyId"); >>> Map(x => x.ExchangeRate, "ExchangeRate"); >>> Map(x => x.Debt, "Debt"); >>> Map(x => x.Receivable, "Receivable"); >>> Map(x => x.LocalDebt, "LocalDebt"); >>> Map(x => x.LocalReceivable, "LocalReceivable"); >>> Map(x => x.IsLock, "IsLock"); >>> Map(x => x.Expiry, "Expiry"); >>> Map(x => x.OpenBalance, "OpenBalance"); >>> Map(x => x.LocalOpenBalance, "LocalOpenBalance"); >>> References(x => x.Invoice, "InvoiceId"); >>> References(x => x.Payment, "PaymentId"); >>> References(x => x.Voucher, "VoucherId"); >>> } >>> } >>> >>> -- >>> Atilla İlhan KARTAL >>> Web Application & Software Architect >>> (Java & PHP & Registered Android Developer) >>> Kuşadası / Aydın / Turkey >>> www.atillailhankartal.com.tr >>> twitter.com/TrojanMyth >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/nhusers. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Atilla İlhan KARTAL > Web Application & Software Architect > (Java & PHP & Registered Android Developer) > Kuşadası / Aydın / Turkey > www.atillailhankartal.com.tr > twitter.com/TrojanMyth > -- Atilla İlhan KARTAL Web Application & Software Architect (Java & PHP & Registered Android Developer) Kuşadası / Aydın / Turkey www.atillailhankartal.com.tr twitter.com/TrojanMyth -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
