views:

524

answers:

2

Suppose I have this class:

public class GroceryListItem()
{
  public GroceryList { get; private set; }

  public GroceryListItem(GroceryList groceryList)
  {
    GroceryList = groceryList;
  }
}

What is the NHibernate mapping file access strategy for this scenario? (i.e. <one-to-many name="GroceryList" column="XXX" access="?????" />)

+1  A: 

Use access="readonly" in the newer versions, or create your own PropertyAccessor or use any of the other approaches described here:

http://blog.schuager.com/2008/12/nhibernate-read-only-property-access.html

asgerhallas
Thank you for the suggestion, but I don't think it applies to this problem. The real answer is actually quite a bit simpler -- no special access is required to handle.
Michael Teper
The access="readonly" is used when you don't have a setter at all.
g .
+2  A: 

It turns out the answer is pretty simple -- no special access is required. NHibernate is smart enough to work this out on its own. In other words, the code in my question works correctly with the following line in the mapping file:

<one-to-many name="GroceryList" column="XXX" />
Michael Teper