I need access to the ApplicationID property of the parent class in order to run an Nhibernate query. Running a test for this query in NUnit causes it to fail as such: "BusinessObjects.IntegrationTests.CMSEligibilityInfoRepositoryTest.FetchListByApplicationIDTest: System.IndexOutOfRangeException : Invalid index 6 for this SqlParameterCollection with Count=6."
This collection of code worked fine before trying to acquire the ApplicationID.
The best my research has come up with so far is that it is a mapping issue.
Parent class:
public abstract class MemberEligibilityInfo
{
#region Access Properties
private int _managedBenOpID;
private int _managedApplicationID;
/// <summary>
/// ID
/// </summary>
public virtual uint ID { get; set; }
/// <summary>
/// MemberElig ID that will work with NHibernate
/// </summary>
public virtual int ManagedMemberEligID { get; set; }
/// <summary>
/// Member ID
/// </summary>
public virtual ulong MemberID { get; set; }
/// <summary>
/// Member ID that will work with NHibernate
/// </summary>
public virtual long ManagedMemberID { get; set; }
/// <summary>
/// Benefit Option ID
/// </summary>
public virtual uint BenefitOptionID { get; set; }
public virtual int ManagedBenOpID
{
get { return _managedBenOpID; }
set
{
if (_managedBenOpID == value)
{
BenefitOptionID = (uint)_managedBenOpID;
return;
}
_managedBenOpID = value;
BenefitOptionID = (uint)_managedBenOpID;
}
}
/// <summary>
/// Benefit Option
/// </summary>
public virtual string UBOI { get; set; }
/// <summary>
/// Application ID
/// </summary>
public virtual uint ApplicationID { get; set; }
public virtual int ManagedApplicationID
{
get { return _managedApplicationID; }
set
{
if (_managedApplicationID == value)
{
ApplicationID = (uint)_managedApplicationID;
return;
}
_managedApplicationID = value;
ApplicationID = (uint)_managedApplicationID;
}
}
/// <summary>
/// Application Plan Year date.
/// </summary>
public virtual DateTime ApplicationPlanYear { get; set; }
/// <summary>
/// Effective Date.
/// </summary>
public virtual DateTime EffectiveDate { get; set; }
/// <summary>
/// Termination Date.
/// </summary>
public virtual DateTime TermDate { get; set; }
#endregion // Access Properties
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public MemberEligibilityInfo()
{
ID = 0;
MemberID = 0;
BenefitOptionID = 0;
UBOI = string.Empty;
ApplicationID = 0;
ApplicationPlanYear = DateTime.MinValue;
EffectiveDate = DateTime.MinValue;
TermDate = DateTime.MinValue;
}
#endregion // Constructors
}
Child class:
public class CMSEligibilityInfo : MemberEligibilityInfo
{
private BenefitOptionInfo _managedBenefitOptionInfo;
#region Access Properties
/// <summary>
/// Precedence
/// </summary>
public virtual int Precedence { get; set; }
/// <summary>
/// Is Active
/// </summary>
public virtual bool Active { get; set; }
public virtual BenefitOptionInfo ManagedBenefitOptionInfo
{
get { return _managedBenefitOptionInfo; }
set
{
if (_managedBenefitOptionInfo == value)
{
return;
}
_managedBenefitOptionInfo = value;
this.ManagedApplicationID = ManagedBenefitOptionInfo.ManagedApplicationID;
}
}
public virtual MemberInfo MemberInfo
{
get;
set;
}
#endregion // Access Properties
#region Constructors
/// <summary>
/// Default Constructor
/// </summary>
public CMSEligibilityInfo() : base()
{
Precedence = 0;
Active = false;
}
#endregion // Constructors
}
Child class mapping:
public class CMSEligibilityInfoMap : ClassMap<CMSEligibilityInfo>
{
public CMSEligibilityInfoMap()
{
// Table
Table("_MEI_EligPeriods");
// Unique Identifier
Id(x => x.ManagedMemberEligID, "MemEligID")
.GeneratedBy.Identity();
// Member ID, Managed to handle the bigint
Map(x => x.ManagedMemberID, "MemberID")
.Not.Nullable();
// Benefit Option ID
Map(x => x.ManagedBenOpID, "BenOpID")
.Not.Nullable();
//// Effective Date
Map(x => x.EffectiveDate, "Eff")
.Nullable();
// Termination Date
Map(x => x.TermDate, "Term")
.Nullable();
// Is the eligibility record active
Map(x => x.Active, "Active")
.Not.Nullable();
Map(x => x.Precedence, "Precedence")
.Nullable();
References(x => x.ManagedBenefitOptionInfo)
.Column("BenOpID")
.Not.LazyLoad()
.Cascade.None();
// References back to MemberInfo
References(x => x.MemberInfo)
.Column("MemberID")
.Not.LazyLoad()
.Cascade.None();
}
}
Query in a repository method that is causing the error:
/// <summary>
/// Fetch a list of eligibility info based on Application ID
/// </summary>
/// <param name="appID">Selected Application ID</param>
/// <returns>A list of eligibility information</returns>
public IList<CMSEligibilityInfo> FetchListByApplicationID(uint? appID)
{
using (var session = SessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var list = session.CreateCriteria<CMSEligibilityInfo>()
.CreateAlias("ManagedBenefitOptionInfo", "ManagedBenefitOptionInfo") .Add(Restrictions.Eq(Projections.Property("ManagedBenefitOptionInfo.ManagedApplicationID"), appID))
.List<CMSEligibilityInfo>();
// Commit the transaction
transaction.Commit();
return list;
}
}
Turns out, this kind of error results from the same property being bound twice, or rather, two properties with the same name were mapped. We removed the parent object (as it was never used) and made the children base classes and made sure the BenefitOptionInfo
object was the only thing mapped through BenOpID
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With