i have an object that have many properties that are lists. to avoid having to do null checks everywhere before i call Add, Count, Clear, etc . . . i thought it would be better to new up all the lists upfront
so inside by Resource object in this case, i have the following code:
public Resource()
{
Regions = new List<Region>();
Directs = new List<Direct>();
}
public virtual IList<Direct> Directs { get; set; }
public virtual IList<Region> Region{ get; set; }
i do get the warning in Visual Studio saying calling virtual methods in the constructor
is there anything wrong or any risk to the code above when using nhibernate ?? if it is wrong, is there a better way of achieving this goal?
That's fine. But if you want a cleaner approach, use:
public Resource()
{
_Regions = new List<Region>();
_Directs = new List<Direct>();
}
IList<Direct> _Directs;
public virtual IList<Direct> Directs { get { return _Directs; } }
IList<Region> _Regions;
public virtual IList<Region> Regions { get { return _Regions; } }
And map with access="nosetter.pascalcase-underscore"
(if you use my naming convention; check the tables at http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-property for other alternatives)