Hi All,
Several of my classes (and tables) contain a validity information (beginDate and endDate fields of "dateTime" type).
I'm trying to implement a <component> containing this info and that could be reused in each class. I'm defining the mapping with mapping attributes in my classes.
As I'm quite a newbie on Nhibernate, my first question is :
Is it the correct way to handle that kind of problems?
I'd like to get this kind of hbm file but through mapping attributes :
Code:
<component name="ValidityPeriod" class="ValidityPeriod">
<property name="BeginDate" access="field" />
<property name="EndDate" access="field" />
</component>
The [component] attribute is a class attribute, then I implemented by ValidityPeriod class like :
Code:
[Component(Name="ValidityPeriod")]
public class ValidityPeriod
{
private static DateTime INFINITE = new DateTime(9999,12,31);
public DateTime _begin;
public DateTime _end; // never null
public DateTime Begin
{
get
{
return _begin;
}
set
{
_begin = value;
}
}
public XsDateTime End
{
get
{
if (_end == INFINITE)
{
return XsDateTime.Null;
}
else
{
return _end;
}
}
set
{
if (value.IsNull)
{
_end = INFINITE;
}
else
{
_end = value;
}
}
}
Is the attribute [component] correctly defined?
What is the attribute I can use to create a property using that component?
Thanks !!
-daV