What are my options for using the null object pattern with Entity Framework? All my business objects have a static ‘Empty’ null object (similar to Guid.Empty, String.Empty and others), and these are assigned to properties of related objects when a null value is selected from the database.
NHibernate supports this pattern through field access with handler code in corresponding properties (an example). How does Entity Framework support this? What about empty lists for one-to-many relations?
The article just uses mapped field and unmapped property – you can use similar approach with two properties in EF. The approach will come with some complications because specifying eager loading is allowed only on mapped properties and lazy loading has also some requirements (dynamic proxy must override the mapped property).
Also whole meaning of null object may be little bit complicated because null with EF means either unassigned or not loaded (if you turn off lazy loading).