I read in the documentation something like : "Properties need not be declared public - NHibernate can persist a property with an internal, protected, protected internal or private visibility."
So, I guess NH should be able to access the property even if the setter is protected. But that is not working for me. I am assuming that the above statement means I don't have to change the access strategy or the naming strategy.
Example:
ClassCode:
public class Candidate
{
virtual public string Number { get; set; }
virtual public DateTime AddedOn { get; protected set; }
virtual public Template Template { get; set; }
virtual public string ZoneName { get; set; }
virtual public DateTime LastActivity { get; set; }
protected Candidate()
{
}
public Candidate
(string number, TemplateType candidateFor, DateTime addedOn, string zoneName)
{
this.Number = number;
this.AddedOn = addedOn;
this.ZoneName = zoneName;
}
public override bool Equals(object obj)
{
Candidate that = obj as Candidate;
if (that == null) return false;
return this.Number.Equals(that.Number);
}
public override int GetHashCode()
{
return this.Number.GetHashCode();
}
}
Here is the mapping:Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MNP_Contracts" namespace="MNP_Contracts">
<class name="Candidate" table="Candidates" dynamic-update="false" lazy="false">
<id name="Number" column="Number">
<generator class="assigned" />
</id>
<property name="AddedOn" column="AddedOn" />
<property name="ZoneName" column="ZoneName" />
<property name="LastActivity" column="LastActivity" />
<many-to-one name="Template" column="TemplateID" />
</class>
</hibernate-mapping>
When loading objects of the above class, the AddedOn property is not set correctly.
What am I missing here?