How to match auto property private set with NHibernate?

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 = "?????" />)

+4
source share
2 answers

It turns out that the answer is quite simple - special access is not required. NHibernate is smart enough to handle this 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" /> 
+4
source

Use access = "readonly" in new versions or create your own PropertyAccessor or use any of the methods described below:

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

+3
source

Source: https://habr.com/ru/post/1285912/


All Articles