在运行时从自己的元数据系统创建 DataAnnotations
例如,我在数据库中存储有关显示列的信息,但我不想使用 DisplayColumnAttribute 来定义它。 我可以做什么来在运行时创建 DataAnnotations 信息?
For example I store information about display column in database and I don't want to use DisplayColumnAttribute for define this. What can I do to create DataAnnotations info in runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

可能您需要使用“DynamicData Buddy Classes”功能。 它允许将验证元数据保存在单独的类中。 因此,您可以创建自定义生成器,该生成器将从数据库生成“好友类”。
更新:检查这篇博文是我今天遇到 DataAnnotations 属性机制的另一个限制时发现的。
Probably you need to use "DynamicData Buddy Classes" feature. It allows holding validation metadata in a separate class. So you can create your custom generator that will generate that "buddy classes" from your database.
Update: Check this blogpost i found today when encountered yet another limitation of DataAnnotations attributes mechanism.