Receiving Index Out of Range with NHibernate - nhibernate

I'm hoping that someone can help me with this issue. I've been racking
my brain and my project is due very soon. Thank You in advance.
I'm receiving an index out of range exception when inserting a new
record. After searching endlessly for information, it was suggested
that the number of column values in my mapping do not match that in my
persistent class. However, I counted and re-counted, and they seem to
match. As you can see by my code below, I'm using
NHibernate.Mapping.Attributes to do my mapping. Maybe I'm doing
something wrong there.
I finally downloaded the NHibernate source and debugged through my
problem. Below is the insert statement that NHibernate is attempting
to build:
{INSERT INTO WTSLIB33T.PRODDATA (PSTAT, PCONO, PDVNO, PWKTY, PCRTY,
PTSID, PCNNO, PDTTK, PJBNO, PSJNO, PTKNO, PCWNO, PWKAR, PWKDC, PWKCD,
PCNWO, PWDNO, PDESC, PDCCD, PHRS, PUNIT, PSEQ, PCUST) VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
As you can see, the number of parameters matches the number of fields
in the list. I've also matched up this generated insert with my class
and what I found is that the PSEQ and PCUST columns are out of order
with my persistent class. Then, while debugging through the Dehydrate
function I found two possible issues. The first is that I noticed that
the call to the NullSafeSet function sets parameter 0 to what my PSEQ
field should be set to but parameter 0 in the insert statement is
PSTAT.
The second issue I noticed is that the very last call "index +=
ArrayHelper.CountTrue(includeColumns[i]);" in the Dehydrate function
leaves the index variable at 23 which is correct; however, the next
call "IdentifierType.NullSafeSet(statement, id, index,
session);" ,where it checks for a row id, passes in index 23 which
would be out of range. This value should be 22 for the zero based
array.
protected int Dehydrate(object id, object[] fields, object rowId, bool[] includeProperty, bool[][] includeColumns, int table, IDbCommand statement, ISessionImplementor session, int index)
{
if (log.IsDebugEnabled)
{
log.Debug("Dehydrating entity: " + MessageHelper.InfoString(this, id, Factory));
}
// there's a pretty strong coupling between the order of the SQL parameter
// construction and the actual order of the parameter collection.
for (int i = 0; i < entityMetamodel.PropertySpan; i++)
{
if (includeProperty[i] && IsPropertyOfTable(i, table))
{
PropertyTypes[i].NullSafeSet(statement, fields[i], index, includeColumns[i], session);
index += ArrayHelper.CountTrue(includeColumns[i]);
}
if (rowId != null)
{
// TODO H3.2 : support to set the rowId
// TransactionManager.manager.SetObject(ps, index, rowId);
// index += 1;
throw new NotImplementedException("support to set the rowId");
}
else if (id != null)
{
IdentifierType.NullSafeSet(statement, id, index, session);
index += IdentifierColumnSpan;
}
return index;
}
MY PERSISTENT CLASS:
[NHibernate.Mapping.Attributes.Class(0, Schema = WTSLIB33T, Table =
"PRODDATA", NameType = typeof(ProddataDAO),
Lazy = true)]
public class ProddataDAO : Object // : INotifyPropertyChanged
{
public ProddataDAO()
{
}
public ProddataDAO(string PSTAT, decimal PCONO, decimal PDVNO, decimal PSEQ, string PWKTY, string PCRTY,
decimal PTSID, decimal PCUST, decimal PCNNO, decimal PDTTK, string PJBNO, string PSJNO, decimal PTKNO,
string PCWNO, string PWKAR, string PWKDC, string PWKCD, string PCNWO, decimal PWDNO, string PDESC,
decimal PDCCD, decimal PHRS, decimal PUNIT)
{
_PSTAT = PSTAT;
_PCONO = PCONO;
_PDVNO = PDVNO;
_PSEQ = PSEQ;
_PWKTY = PWKTY;
_PCRTY = PCRTY;
_PTSID = PTSID;
_PCUST = PCUST;
_PCNNO = PCNNO;
_PDTTK = PDTTK;
_PJBNO = PJBNO;
_PSJNO = PSJNO;
_PTKNO = PTKNO;
_PCWNO = PCWNO;
_PWKAR = PWKAR;
_PWKDC = PWKDC;
_PWKCD = PWKCD;
_PCNWO = PCNWO;
_PWDNO = PWDNO;
_PDESC = PDESC;
_PDCCD = PDCCD;
_PHRS = PHRS;
_PUNIT = PUNIT;
}
//public event PropertyChangedEventHandler PropertyChanged;
private decimal _PSEQ;
//[NHibernate.Mapping.Attributes.Id(0, Name="PSEQ", Column="PSEQ", Type="Decimal")]
[NHibernate.Mapping.Attributes.CompositeId(1, UnsavedValue=NHibernate.Mapping.Attributes.UnsavedValueType.Undefined)]
[NHibernate.Mapping.Attributes.KeyProperty(2, Name = "PSEQ", Column = "PSEQ", Type="Decimal")]
[NHibernate.Mapping.Attributes.KeyProperty(2, Name = "PCUST", Column = "PCUST")]
//[NHibernate.Mapping.Attributes.Generator(3, Class="none")]
[NHibernate.Mapping.Attributes.Property(4, Name="PSEQ", Column="PSEQ")]
public virtual decimal PSEQ
{
get
{
return _PSEQ;
}
set
{
if (value != this._PSEQ)
{
_PSEQ = value;
//OnPropertyChanged("PSEQ");
}
}
}
private decimal _PCUST;
//[NHibernate.Mapping.Attributes.Id(0, Column = "PCUST", Type = "Decimal")]
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PCUST
{
get
{
return _PCUST;
}
set
{
if (value != this._PCUST)
{
_PCUST = value;
//OnPropertyChanged("PCUST");
}
}
}
private string _PSTAT;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PSTAT
{
get
{
return _PSTAT;
}
set
{
if (value != this._PSTAT)
{
this._PSTAT = value;
//OnPropertyChanged("PSTAT");
}
}
}
private decimal _PCONO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PCONO
{
get
{
return _PCONO;
}
set
{
if (value != this._PCONO)
{
_PCONO = value;
//OnPropertyChanged("PCONO");
}
}
}
private decimal _PDVNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PDVNO
{
get
{
return _PDVNO;
}
set
{
if (value != this._PDVNO)
{
_PDVNO = value;
//OnPropertyChanged("PDVNO");
}
}
}
private string _PWKTY;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PWKTY
{
get
{
return _PWKTY;
}
set
{
if (value != this._PWKTY)
{
_PWKTY = value;
//OnPropertyChanged("PWKTY");
}
}
}
private string _PCRTY;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PCRTY
{
get
{
return _PCRTY;
}
set
{
if (value != this._PCRTY)
{
_PCRTY = value;
//OnPropertyChanged("PCRTY");
}
}
}
private decimal _PTSID;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PTSID
{
get
{
return _PTSID;
}
set
{
if (value != this._PTSID)
{
_PTSID = value;
//OnPropertyChanged("PTSID");
}
}
}
private decimal _PCNNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PCNNO
{
get
{
return _PCNNO;
}
set
{
if (value != this._PCNNO)
{
_PCNNO = value;
//OnPropertyChanged("PCNNO");
}
}
}
private decimal _PDTTK;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PDTTK
{
get
{
return _PDTTK;
}
set
{
if (value != this._PDTTK)
{
_PDTTK = value;
//OnPropertyChanged("PDTTK");
}
}
}
private string _PJBNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PJBNO
{
get
{
return _PJBNO;
}
set
{
if (value != this._PJBNO)
{
_PJBNO = value;
//OnPropertyChanged("PJBNO");
}
}
}
private string _PSJNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PSJNO
{
get
{
return _PSJNO;
}
set
{
if (value != this._PSJNO)
{
_PSJNO = value;
//OnPropertyChanged("PSJNO");
}
}
}
private decimal _PTKNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PTKNO
{
get
{
return _PTKNO;
}
set
{
if (value != this._PTKNO)
{
_PTKNO = value;
//OnPropertyChanged("PTKNO");
}
}
}
private string _PCWNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PCWNO
{
get
{
return _PCWNO;
}
set
{
if (value != this._PCWNO)
{
_PCWNO = value;
//OnPropertyChanged("PCWNO");
}
}
}
private string _PWKAR;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PWKAR
{
get
{
return _PWKAR;
}
set
{
if (value != this._PWKAR)
{
_PWKAR = value;
//OnPropertyChanged("PWKAR");
}
}
}
private string _PWKDC;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PWKDC
{
get
{
return _PWKDC;
}
set
{
if (value != this._PWKDC)
{
_PWKDC = value;
//OnPropertyChanged("PWKDC");
}
}
}
private string _PWKCD;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PWKCD
{
get
{
return _PWKCD;
}
set
{
if (value != this._PWKCD)
{
_PWKCD = value;
//OnPropertyChanged("PWKCD");
}
}
}
private string _PCNWO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PCNWO
{
get
{
return _PCNWO;
}
set
{
if (value != this._PCNWO)
{
_PCNWO = value;
//OnPropertyChanged("PCNWO");
}
}
}
private decimal _PWDNO;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PWDNO
{
get
{
return _PWDNO;
}
set
{
if (value != this._PWDNO)
{
_PWDNO = value;
//OnPropertyChanged("PWDNO");
}
}
}
private string _PDESC;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual string PDESC
{
get
{
return _PDESC;
}
set
{
if (value != this._PDESC)
{
_PDESC = value;
//OnPropertyChanged("PDESC");
}
}
}
private decimal _PDCCD;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PDCCD
{
get
{
return _PDCCD;
}
set
{
if (value != this._PDCCD)
{
_PDCCD = value;
//OnPropertyChanged("PDCCD");
}
}
}
private decimal _PHRS;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PHRS
{
get
{
return _PHRS;
}
set
{
if (value != this._PHRS)
{
_PHRS = value;
//OnPropertyChanged("PHRS");
}
}
}
private decimal _PUNIT;
[NHibernate.Mapping.Attributes.Property(4)]
public virtual decimal PUNIT
{
get
{
return _PUNIT;
}
set
{
if (value != this._PUNIT)
{
_PUNIT = value;
//OnPropertyChanged("PUNIT");
}
}
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
ProddataDAO p = obj as ProddataDAO;
if (this.PCONO == p.PCONO && this.PDVNO == p.PDVNO && this.PCUST == p.PCUST && this.PSEQ == p.PSEQ)
return true;
else
return false;
}
public override int GetHashCode()
{
int hash = 1122;
hash += (null == this.PCONO ? 0 : this.PCONO.GetHashCode());
hash += (null == this.PDVNO ? 0 : this.PDVNO.GetHashCode());
hash += (null == this.PCUST ? 0 : this.PCUST.GetHashCode());
hash += (null == this.PSEQ ? 0 : this.PSEQ.GetHashCode());
return hash;
}

One possible cause for this problem is that you have mapped two properties to the same column. For example you have mapped a foreign key relation as a relation and as a property field, or you have a descriminator that you also have mapped as a field.
Looking at the primary key mapping I see that it is mapped twice:
[NHibernate.Mapping.Attributes.CompositeId(1, UnsavedValue=NHibernate.Mapping.Attributes.UnsavedValueType.Undefined)]
[NHibernate.Mapping.Attributes.KeyProperty(2, Name = "PSEQ", Column = "PSEQ", Type="Decimal")]
[NHibernate.Mapping.Attributes.KeyProperty(2, Name = "PCUST", Column = "PCUST")]
//[NHibernate.Mapping.Attributes.Generator(3, Class="none")]
[NHibernate.Mapping.Attributes.Property(4, Name="PSEQ", Column="PSEQ")]
Are you sure this is the way to map a composite key with NHiberante attributes? I haven't used it myself. But my guess is that it is this that is causing NHibernate to think that you have mapped the column PSEQ twice.
I think you should only use the KeyProperty and skip the Property attribute for the properties that belong to the primary key.
Try adding this in the top section of the class (do not adorn the property declarations)
[CompositeId(1,UnsavedValue=UnsavedValueType.Undefined)]
[KeyProperty(2, Name="PSEQ", Column="PSEQ")]
[KeyProperty(4, Name="PCUST", Column="PCUST")]
Found this leated forum thread: https://forum.hibernate.org/viewtopic.php?f=25&t=964631&start=0

i had a similar situation when using XML mapping, we had originally included the "parent id" column in the .hbm.xml, then when we went to add the back-reference via a many-to-one tag i received the index out of range exception. removing the original declaration was the key.
<class name="IncomeDetail" table="INCOMEDETAILS" mutable="true" lazy="false">
<id name="IncomeDetailID" column="INCOME_DETAIL_ID">
<generator class="native" />
</id>
<property name='ParticipantID' column='PARTICIPANT_ID' type='Int32'/>
<property name='IncomeGroupCD' column='INCOME_GROUP_CD' type='String'/>
<property name='IncomeTypeID' column='INCOME_TYPE_ID' type='Int32'/>
<!--<property name='EmploymentID' column='EMPLOYMENT_ID' type='Int32'/>-->
<property name='IncomeFrequencyCD' column='INCOME_FREQUENCY_CD' type='String'/>
<property name='CapturedDetGrossIncomeAmt' column='CAPTURED_DET_GROSS_INCOME_AMT' type='Decimal'/>
<property name='CapturedDetNetIncomeAmt' column='CAPTURED_DET_NET_INCOME_AMT' type='Decimal'/>
<property name='VerifiedDetGrossIncomeAmt' column='VERIFIED_DET_GROSS_INCOME_AMT' type='Decimal'/>
<property name='VerifiedDetNetIncomeAmt' column='VERIFIED_DET_NET_INCOME_AMT' type='Decimal'/>
<property name='IncomeDesc' column='INCOME_DESC' type='String'/>
<property name='CapturedDT' column='CAPTURED_DT' type='DateTime' not-null='true'/>
<property name='CapturedBy' column='CAPTURED_BY' type='String' not-null='true'/>
<property name='VerificationDT' column='VERIFICATION_DT' type='DateTime' />
<property name='VerifiedBy' column='VERIFIED_BY' type='String' />
<property name='VefificationSourceCD' column='VEFIFICATION_SOURCE_CD' type='String'/>
<many-to-one name="EmploymentIncome" column="EMPLOYMENT_ID" />
</class>

Related

how to pass two or three values to fluent validation Must function?

my code :
public class MandatoryValidator : AbstractValidator<Entity.EigenSchema.AttributeSet>
{
private string Keyvalue = string.Empty;
public MandatoryValidator(string keyvalue)
{
Keyvalue = keyvalue;
RuleFor(record => record.Mandatory).Must(Mandatory);
}
protected bool Mandatory(bool val)
{
if (val)
{
if(Keyvalue!=null || Keyvalue!="")
{
return true;
}
return false;
}
else
{
return true;
}
}
}
this checks if the field is mandatory or not.
Now I need a function that takes more than one parameter to mandatory function, something like this..
protected bool Mandatory(bool val, string strval, int val)
{
//strval = record.LocalUnique
//val = record.Size
}
You can do it like this
RuleFor(record => record.Mandatory).Must(mandatoryField => Mandatory(mandatoryField, Keyvalue, 012));
You can also
RuleFor(record => record).Must(WholeObject=> Mandatory(WholeObject))
.WithName("Mandatory");
//.WithName(x => x.MandatoryFieldName) optional
//and now
private bool MandatorChecker(MyRecordType obj)
{
strval = obj.LocalUnique;
val = obj.Size;
}
This one will use the name you provided if this rule breaks.

Acumatica How to get the Cash Account Begin or Ending Balance?

When I select a Cash Account in the "Founds Transfers" (CA301000), GL Balance and Avaliable Balance Entries are updated.
Where these amounts come from? I mean, I need to query these field via GI but I cannot figure out the Table's name.
Any Clues?
GL Balance and Available Balance fields are part of the CATransfer DAC.
You won't find them in the CATransfer database table because they are calculated at runtime in CATransfer DAC as unbound fields using the FieldSelecting events of GLBalanceAttribute and CashBalanceAttribute.
You can find out the DAC and Data Field of a UI element by holding Ctl+Alt and clicking on that field.
For reference, here are the GLBalance attributes inCATransfer Dac:
#region InGLBalance
public abstract class inGLBalance : PX.Data.IBqlField
{
}
protected Decimal? _InGLBalance;
[PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
[PXCury(typeof(CATransfer.inCuryID))]
[PXUIField(DisplayName = "GL Balance", Enabled = false)]
[GLBalance(typeof(CATransfer.inAccountID), null, typeof(CATransfer.inDate))]
public virtual Decimal? InGLBalance
{
get
{
return this._InGLBalance;
}
set
{
this._InGLBalance = value;
}
}
#endregion
#region OutGLBalance
public abstract class outGLBalance : PX.Data.IBqlField
{
}
protected Decimal? _OutGLBalance;
[PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
[PXCury(typeof(CATransfer.outCuryID))]
[PXUIField(DisplayName = "GL Balance", Enabled = false)]
[GLBalance(typeof(CATransfer.outAccountID), null, typeof(CATransfer.outDate))]
public virtual Decimal? OutGLBalance
{
get
{
return this._OutGLBalance;
}
set
{
this._OutGLBalance = value;
}
}
#endregion
Here is the GLBalanceAttribute class FieldSelecting event where the value is calculated:
public virtual void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
GLSetup gLSetup = PXSelect<GLSetup>.Select(sender.Graph);
decimal? result = 0m;
object CashAccountID = sender.GetValue(e.Row, _CashAccount);
object FinPeriodID = null;
if (string.IsNullOrEmpty(_FinPeriodID))
{
object FinDate = sender.GetValue(e.Row, _FinDate);
FinPeriod finPeriod = PXSelect<FinPeriod, Where<FinPeriod.startDate, LessEqual<Required<FinPeriod.startDate>>,
And<FinPeriod.endDate, Greater<Required<FinPeriod.endDate>>>>>.Select(sender.Graph, FinDate, FinDate);
if (finPeriod != null)
{
FinPeriodID = finPeriod.FinPeriodID;
}
}
else
{
FinPeriodID = sender.GetValue(e.Row, _FinPeriodID);
}
if (CashAccountID != null && FinPeriodID != null)
{
// clear glhistory cache for ReleasePayments longrun
sender.Graph.Caches<GLHistory>().ClearQueryCache();
sender.Graph.Caches<GLHistory>().Clear();
GLHistory gLHistory = PXSelectJoin<GLHistory,
InnerJoin<GLHistoryByPeriod,
On<GLHistoryByPeriod.accountID, Equal<GLHistory.accountID>,
And<GLHistoryByPeriod.branchID, Equal<GLHistory.branchID>,
And<GLHistoryByPeriod.ledgerID, Equal<GLHistory.ledgerID>,
And<GLHistoryByPeriod.subID, Equal<GLHistory.subID>,
And<GLHistoryByPeriod.lastActivityPeriod, Equal<GLHistory.finPeriodID>>>>>>,
InnerJoin<Branch,
On<Branch.branchID, Equal<GLHistory.branchID>,
And<Branch.ledgerID, Equal<GLHistory.ledgerID>>>,
InnerJoin<CashAccount,
On<GLHistoryByPeriod.branchID, Equal<CashAccount.branchID>,
And<GLHistoryByPeriod.accountID, Equal<CashAccount.accountID>,
And<GLHistoryByPeriod.subID, Equal<CashAccount.subID>>>>,
InnerJoin<Account,
On<GLHistoryByPeriod.accountID, Equal<Account.accountID>,
And<Match<Account, Current<AccessInfo.userName>>>>,
InnerJoin<Sub,
On<GLHistoryByPeriod.subID, Equal<Sub.subID>, And<Match<Sub, Current<AccessInfo.userName>>>>>>>>>,
Where<CashAccount.cashAccountID, Equal<Required<CashAccount.cashAccountID>>,
And<GLHistoryByPeriod.finPeriodID, Equal<Required<GLHistoryByPeriod.finPeriodID>>>
>>.Select(sender.Graph, CashAccountID, FinPeriodID);
if (gLHistory != null)
{
result = gLHistory.CuryFinYtdBalance;
}
}
e.ReturnValue = result;
e.Cancel = true;
}
}
Here are the CashBalance attributes of CATransfer Dac:
#region CashBalanceIn
public abstract class cashBalanceIn : PX.Data.IBqlField
{
}
protected Decimal? _CashBalanceIn;
[PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
[PXCury(typeof(CATransfer.inCuryID))]
[PXUIField(DisplayName = "Available Balance", Enabled = false)]
[CashBalance(typeof(CATransfer.inAccountID))]
public virtual Decimal? CashBalanceIn
{
get
{
return this._CashBalanceIn;
}
set
{
this._CashBalanceIn = value;
}
}
#endregion
#region CashBalanceOut
public abstract class cashBalanceOut : PX.Data.IBqlField
{
}
protected Decimal? _CashBalanceOut;
[PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
[PXCury(typeof(CATransfer.outCuryID))]
[PXUIField(DisplayName = "Available Balance", Enabled = false)]
[CashBalance(typeof(CATransfer.outAccountID))]
public virtual Decimal? CashBalanceOut
{
get
{
return this._CashBalanceOut;
}
set
{
this._CashBalanceOut = value;
}
}
#endregion
And the CashBalanceAttribute class FieldSelecting event where the value is calculated:
public virtual void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
{
CASetup caSetup = PXSelect<CASetup>.Select(sender.Graph);
decimal? result = 0m;
object CashAccountID = sender.GetValue(e.Row, _CashAccount);
CADailySummary caBalance = PXSelectGroupBy<CADailySummary,
Where<CADailySummary.cashAccountID, Equal<Required<CADailySummary.cashAccountID>>>,
Aggregate<Sum<CADailySummary.amtReleasedClearedCr,
Sum<CADailySummary.amtReleasedClearedDr,
Sum<CADailySummary.amtReleasedUnclearedCr,
Sum<CADailySummary.amtReleasedUnclearedDr,
Sum<CADailySummary.amtUnreleasedClearedCr,
Sum<CADailySummary.amtUnreleasedClearedDr,
Sum<CADailySummary.amtUnreleasedUnclearedCr,
Sum<CADailySummary.amtUnreleasedUnclearedDr>>>>>>>>>>.
Select(sender.Graph, CashAccountID);
if ((caBalance != null) && (caBalance.CashAccountID != null))
{
result = caBalance.AmtReleasedClearedDr - caBalance.AmtReleasedClearedCr;
if ((bool)caSetup.CalcBalDebitClearedUnreleased)
result += caBalance.AmtUnreleasedClearedDr;
if ((bool)caSetup.CalcBalCreditClearedUnreleased)
result -= caBalance.AmtUnreleasedClearedCr;
if ((bool)caSetup.CalcBalDebitUnclearedReleased)
result += caBalance.AmtReleasedUnclearedDr;
if ((bool)caSetup.CalcBalCreditUnclearedReleased)
result -= caBalance.AmtReleasedUnclearedCr;
if ((bool)caSetup.CalcBalDebitUnclearedUnreleased)
result += caBalance.AmtUnreleasedUnclearedDr;
if ((bool)caSetup.CalcBalCreditUnclearedUnreleased)
result -= caBalance.AmtUnreleasedUnclearedCr;
}
e.ReturnValue = result;
e.Cancel = true;
}
}

How to map collections in proper way

What is the best way for mapping collection of objects in NHibernate?
Now I am using bags, but maybe another approach can be more efficient?
Before wore Bag and ClassMapping, something very similar to this:
Bag(am => am.AlumnoMateriaId, map =>
{
map.Table("Calificacion");
map.Cascade(Cascade.None);
map.Key(k =>
{
k.Column("AlumnoId");
k.ForeignKey("FK_Calificacion_AlumnoMateria");
});
}, rel => rel.ManyToMany(p => p.Column("AlumnoId")));
Now Use the NHibernate.Mapping.Attributes, and a class would look like:
using NHMA = NHibernate.Mapping.Attributes;
[NHMA.Class(Table = " Calificacion ")]
public class Calificacion
{
[NHMA.Id(0, Name = "id", TypeType = typeof(Int32), Column = "Id", Access = "field")]
[NHMA.Generator(1, Class = "native")]
public Int32 id;
public virtual Int32 Id
{
get { return id; }
set { id = value; }
}
[NHMA.ManyToOne(2, Name = "calificacion", Access = "field", Column = "CalificacionID",
Class = "Calificacion", ClassType = typeof(Calificacion),
ForeignKey = "FK_Calificacion_Alumno", NotNull = false)]
private Calificacion calificaion;
public virtual Calificacion Calificaion
{
get { return calificaion; }
set { calificaion = value; }
}
[NHMA.Property(Name = "nombre", Access = "field", Column = "Nombre", Length = 50)]
private string nombre;
public virtual string Nombre
{
get { return nombre; }
set { nombre = value; }
}
}

Class is CLS Compliant to .NET but not in Mono

I had to build my own Version class. In .NET it's CLS Compliant but in Mono its not for some reason. Any ideas why?
[Serializable]
public class Version : ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
{
private int major;
private int minor;
private int revision;
private int build;
protected Version()
{
}
public Version(int major, int minor)
{
Major = major;
Minor = minor;
}
public Version(int major, int minor, int revision, int build) : this(major, minor)
{
Revision = revision;
Build = build;
}
public Version(string version)
{
if (string.IsNullOrWhiteSpace(version))
{
throw new ControlInfluence.Exceptions.ArgumentNullStringException("version");
}
string[] parts = version.Split('.');
if ((parts.Length != 4) && (parts.Length != 2))
{
throw new ArgumentException("'version' must have 2 or 4 numbers separated by '.'.", "version");
}
if (!int.TryParse(parts[0], out major))
{
throw new ArgumentException("'version' must have 2 or 4 numbers separated by '.'.", "version");
}
if (!int.TryParse(parts[1], out minor))
{
throw new ArgumentException("'version' must have 2 or 4 numbers separated by '.'.", "version");
}
if (!int.TryParse(parts[2], out revision))
{
throw new ArgumentException("'version' must have 2 or 4 numbers separated by '.'.", "version");
}
if (!int.TryParse(parts[3], out build))
{
throw new ArgumentException("'version' must have 2 or 4 numbers separated by '.'.", "version");
}
}
public int Major
{
get
{
return major;
}
set
{
major = value;
}
}
public int Minor
{
get
{
return minor;
}
set
{
minor = value;
}
}
public int Build
{
get
{
return build;
}
set
{
build = value;
}
}
public int Revision
{
get
{
return revision;
}
set
{
revision = value;
}
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", Major, Minor, Revision, Build);
}
public static bool operator <(Version left, Version right)
{
if ((left == null) || (right == null))
{
return false;
}
return left.CompareTo(right) < 0;
}
public static bool operator >(Version left, Version right)
{
if ((left == null) || (right == null))
{
return false;
}
return left.CompareTo(right) > 0;
}
#region ICloneable Members
public object Clone()
{
return new Version(Major, Minor, Revision, Build);
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
Version other = obj as Version;
if (other == null)
{
return -1;
}
return CompareTo(other);
}
#endregion
#region IComparable<Version> Members
public int CompareTo(Version other)
{
if (other == null)
{
return -1;
}
int compareMajor = Major.CompareTo(other.Major);
if (compareMajor != 0)
{
return compareMajor;
}
int compareMinor = Minor.CompareTo(other.Minor);
if (compareMinor != 0)
{
return compareMinor;
}
int compareRevision = Revision.CompareTo(other.Revision);
if (compareRevision != 0)
{
return compareRevision;
}
return Build.CompareTo(other.Build);
}
#endregion
#region IEquatable<Version> Members
public bool Equals(Version other)
{
return CompareTo(other) == 0;
}
#endregion
public override bool Equals(object obj)
{
Version version = obj as Version;
if (version == null)
{
return false;
}
return Equals(version);
}
public static bool operator ==(Version left, Version right)
{
if (Object.ReferenceEquals(left, null) && Object.ReferenceEquals(right, null))
{
return true;
}
if (Object.ReferenceEquals(left, null) || Object.ReferenceEquals(right, null))
{
return false;
}
return left.Equals(right);
}
public static bool operator !=(Version left, Version right)
{
if ((left == null) || (right == null))
{
return false;
}
return !left.Equals(right);
}
}
The custom exception classes I throw are simply wrappers around ArgumentNullException that "auto fill" the message for me so they aren't adding any types to it really.
If it's CLS compliant in .NET but not on Mono, it is a bug in Mono. Please file a bug in http://bugzilla.xamarin.com

two way mapping

Is any way, how to create two classes, which will be referenced both way and will use only one FK? This interest me in One-to-One as like as One-to-Many cases.
f.e.:
Class First: Entity
{
Second second;
}
Class Second: Entity
{
First first;
}
String TwoWayReference()
{
First Fir = new First();
Second Sec = new Second();
Fir.second = Sec; // I need it is equivalent to: Sec.first = Fir;
if (Sec.first == Fir)
return "Is any way how to do this code works and code return this string?";
else
return "Or it is impossible?"
}
simplest would be
class First : Entity
{
private Second second;
public virtual Second Second
{
get { return this.second; }
set {
if (value != null)
{
value.First = this;
this.second = value;
}
}
}
}
class Second : Entity
{
private First first;
public virtual First First
{
get { return this.first; }
set {
if (value != null && value.Second != this)
{
value.Second = this;
this.first = value;
}
}
}
}