C# 自定义属性访问数据库

发布于 2024-09-15 18:17:25 字数 196 浏览 3 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沦落红尘 2024-09-22 18:17:25

在我的书中,让属性执行数据库操作感觉有点奇怪。也就是说,例如,每次调用 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.

烟燃烟灭 2024-09-22 18:17:25

属性通常不做任何事情。他们是标记。其他代码应该使用它们来根据属性中使用的数据执行某些操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文