我创建了私有字段并在类的构造函数中初始化它。
#region "Private Fields"
private readonly IList<Ethnicity> _ethnicities;
private readonly IList<Contact> _contacts;
private readonly IList<Address> _addresses;
private readonly IList<Dependent> _dependents;
private readonly IList<InsuredType> _insuredTypes;
private const string PrimaryEmailCode = "EML";
private const string SecondaryEmailCode = "EM2";
private const string HomePhoneCode = "HPH";
private const string CellPhoneCode = "CPH";
private const string PrimaryInsured = "PRIMARY";
private const string DependentInsured = "DEPENDENT";
private const string PermenantAddressCode = "PERM";
private const string MailingAddressCode = "MAIL";
#endregion
#region "Constructors"
public Insured()
{
_ethnicities = new List<Ethnicity>();
_contacts = new List<Contact>();
_addresses = new List<Address>();
_dependents = new List<Dependent>();
_insuredTypes = new List<InsuredType>();
}
#endregion
#region "Public Properties"
public virtual IEnumerable<InsuredType> Insuredtypes
{
get { return _insuredTypes; }
}
public virtual string InsuredType
{
get
{
if (InsuredStatus == "ACTIVE")
{
var type = _insuredTypes.FirstOrDefault(n => n.ExpiryDate > DateTime.Now);
if (type != null)
{
var status = type.InsuredTypeDescription == "PRIM" ? PrimaryInsured : DependentInsured;
return status;
}
}
if (InsuredStatus == "EXPIRED" || InsuredStatus == "MERGED")
{
var type =
_insuredTypes.Where(n => n.ExpiryDate < DateTime.Now)
.OrderByDescending(n => n.ExpiryDate)
.FirstOrDefault();
if (type != null)
{
var status = type.InsuredTypeDescription == "PRIM" ? PrimaryInsured : DependentInsured;
return status;
}
}
return string.Empty;
}
}
当我运行它时,我得到_insuredTypes could not found in Insured class
。
有谁可以指出我做错了什么?
以下是保险类
的映射internal class InsuredMap : CacheableEntityClassMap<Entities.Insured>
{
public InsuredMap()
{
ReadOnly();
Table("Insured");
Id(x => x.Id, "InsuredId");
Map(x => x.Gender,Convert.ToString("SexCd")).CustomType<TrimmedStringUserType>();
Map(x => x.GradDate, Convert.ToString("GradMthYrNum")).CustomType<TrimmedStringUserType>();
Map(x => x.SrId, Convert.ToString("SIDIdNum")).CustomType<TrimmedStringUserType>();
Map(x => x.SchoolId, Convert.ToString("SchoolIdTxt")).CustomType<TrimmedStringUserType>();
Map(x => x.Ssn, Convert.ToString("SocSecNumTxt")).CustomType<TrimmedStringUserType>();
Map(x => x.DateOfBirth, Convert.ToString("BirthDt")).CustomType<TrimmedStringUserType>();
Map(x => x.ExpDt, ("ExpDt"));
这里是保险类型的映射
HasMany(x => x.Insuredtypes)
.KeyColumn("InsuredId")
.LazyLoad()
.Inverse()
.Cascade.All();
答案 0 :(得分:1)
看起来你将_insuredTypes
属性设置为private,因此NHibernate无法找到要映射的字段。如果要映射它并将其设置为只读,则需要查看不同于默认值的映射选项。
如需额外帮助 - 您应该发布您的映射。