开发者

What is the best practice when you have read-only properties and cannot use the objectdatasource?

开发者 https://www.devze.com 2023-01-22 12:24 出处:网络
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

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


You can map the nHibernate to fields. This may help NHibernate : map to fields or properties?

This way you should be able to have RO properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号