C# 自定义属性访问数据库
我有一个使用 nhiberate 访问数据库的自定义属性。该属性实际上继承自 Castle 的 AbstractValidationAttribute,用于根据正则表达式验证属性。问题是,这些正则表达式由cms管理并存储在数据库中,当您更改数据库中的值时,它们不会反映在属性中。基本上,该属性仅初始化,因此从数据库加载一次。有什么办法解决这个问题吗?
谢谢,罗宾
I have a custom attribute that accesses the database with nhiberate. The attribute actually inherits from Castle's AbstractValidationAttribute and is used to validate properties against regular expressions. Problem is, these regular expressions are cms managed and stored in the database, and when you change the values in the database, they are not reflected in the attribute. Basically, the attribute only initializes and there fore loads from the database once. Is there any way around this?
Thanks, Robin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的书中,让属性执行数据库操作感觉有点奇怪。也就是说,例如,每次调用 GetCustomAttributes 时都会实例化属性对象,因此,如果属性在其构造过程中获取数据,则每当使用该方法检查属性时,它都应该获取该数据。
In my book it feels a bit odd to have an attribute perform database operations. That said, the attribute object is instantiated each time you call
GetCustomAttributes
for instance, so if the attribute picks up the data as part of its construction, it should fetch it whenever attributes are inspected using that method.属性通常不做任何事情。他们是标记。其他代码应该使用它们来根据属性中使用的数据执行某些操作。
Attributes generally don't do anything. They are markers. Other code should use them to perform some operation based on the data used in the attribute.