NHibernate needs to have a place to "hold" the data that we are storing in the database. In order for NHibernate to do its job, we need to create some public properties to contain the data.
A property is simply a way to set and get data. We define a property by declaring a private variable to hold the actual data and some combination of a getter and/or a setter to manipulate the value in the private variable.
In C#, a property looks something as follows:
private int _id; public int Id { get { return _id; } set { _id = value; } }
While in VB.NET, it will look as follows:
Private _id As Integer Public Property Id() As Integer Get Return _id End Get Set(ByVal value As Integer) _id = value End Set End Property
It is possible to create a ReadOnly
property where a user has no access to the setter, that is, the only way to set the value is by manipulating the private variable from within the class itself. A ReadOnly
property will look very similar...