I am working on my first NHibernate project, so this may seem like a simple question.
The following is a simplified one from my real scenario to convey a specific question.
Suppose I have a Customer object
public class Customer
{
prop virtual int ID { get; set; }
prop virtual string Name { get; set; }
prop virtual Region Region { get; set; }
}
and my subject of the region (the regions are similar, NorthWest, MidWest, etc. - a pretty specific list, which will be in some kind of drop-down list)
public class Region
{
prop virtual int ID { get; set; }
prop virtual string Name { get; set; }
private readonly IList<Customer> _customers = new List<Customer>();
public virtual void Add(Customer customer)
{
_customers.Add(customer);
}
public virtual void Remove(Customer customer)
{
_customers.Remove(customer);
}
public virtual Customer[] GetCustomers()
{
return _customers.ToArray();
}
}
When I go to Persist Customer Entity, I really want to have only 3 pieces of information (Customer.ID, Customer.Name and Customer.Region.ID) how to do this because NHibernate expects a client object that includes the full Region object (and not only identifier) ...