views:

8

answers:

1

I have started a web forms project using nHibernate and objectdatasources; however, I've learned that there are some limitations that I understand but do not know to handle. These limitations include 1) objectdatasources require parameterless constructors and 2) properties of the business object cannot be read-only.

The problem I'm having is that a class in my business layer sets a property that should never change and I'd like to make sure this never happens. I'd like to set that property when the object is created, but make the property read-only so people cannot set it later. I'm not sure it's relevant to the issue, but I am using a repository class as well.

I guess I could simply make the property read/write, but I think that the business layer should enforce the rule of never changing the property. Is there a way to use objectdatasources without relaxing my business rule that a property must be read-only. If I cannot use objectdatasources, is there another best practice that does not include copying the logic of creating objects, setting their properties based on form values and then saving?

Thanks for any insight on this issue. I'm sure people have come across this in the past so I'm just looking for some direction in how to best use data sources for a web forms site. Also, any references to books or articles related to handling not so typical issues would be helpful. It seems like everything I've been looking at has you building CRUD screens...

  • Sean
A: 

You can map the nHibernate to fields. This may help http://stackoverflow.com/questions/129773/nhibernate-map-to-fields-or-properties/129805#129805

This way you should be able to have RO properties.

Preet Sangha