如何将 [ScaffoldColumn(false)] 设置为动态数据的默认值?
我有许多包含很多列的表,我正在使用动态数据。我只想显示一小部分列。
目前,当动态数据搭建表时,它会创建所有列,除非我将 [ScaffoldColumn(false)] 设置为 false。这是可行的,但由于我只想显示列的一小部分,因此打开它们比关闭它们更容易。
有没有办法更改默认行为,以便除非我告诉它,否则列不会被搭建起来?
I have a number of tables with lots of columns that I'm using Dynamic Data with. I only want to show a small subset of the columns.
Currently when Dynamic Data scaffolds a table it creates all the columns unless I set [ScaffoldColumn(false)] to false. This works but as I only want to display a small subset of the columns it would be easier to turn them on rather than off.
Is there a way to change the default behaviour so a column is not scaffolded unless I tell it to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道有什么方法可以开箱即用地做到这一点。但是,您可以创建自己的自定义属性来执行此操作。
以下是有关如何创建自定义属性来控制 DD 工作方式的一些示例:
http://csharpbits.notaclue.net/2009/04/hiding-foreign-key-column-globally-in.html - 创建属性以隐藏外键列的示例所有桌子。
http://csharpbits.notaclue.net/ 2008/10/dynamic-data-hiding-columns-in-selected.html - 用于隐藏列但应用于页面级别的另一个属性的示例。
我看到第一个它是在表级别定义的,也许是您最好的选择。您可以创建自己的属性(例如 HideFieldsByDefault)并将其设置为 true。
然后,您将希望使用 ScaffoldColumn 显示的字段添加为 true,然后在 IAutoFieldGenerator 的GenerateFields 方法的代码中,您将相应地查找您的自定义属性和代码,如果您的属性不是他们的,那么您只需使用默认DD方式。
您也可以使用自己的元数据提供程序来执行此操作:
http://mattberseth。 com/blog/2008/08/dynamic_data_and_custom_metada.html
在这方面,我不确定如何使用自定义提供程序来做到这一点,但也许一点研究会表明它是一个不错的选择。
I don't know of a way to do this out of the box. However, you can create your own custom attribute to do this.
Here's some samples on how to create a custom attribute to control how DD works:
http://csharpbits.notaclue.net/2009/04/hiding-foreign-key-column-globally-in.html - Sample of creating an attribute to hide the foreign key column for all tables.
http://csharpbits.notaclue.net/2008/10/dynamic-data-hiding-columns-in-selected.html - Sample of another attribute to hide a column but applied at the page level.
I see the first one where it's defined at the table level perhaps your best bet. You could create your own attribute say HideFieldsByDefault and set it to true.
You would then add your fields that you want to be shown with ScaffoldColumn to true and in the code for the IAutoFieldGenerator's GenerateFields method you would then look for your custom attribute and code accordingly and if your attribute wasn't their then you would just use the default DD way.
You might also be able to do this with your own metadata provider:
http://mattberseth.com/blog/2008/08/dynamic_data_and_custom_metada.html
On this one, I'm not sure exactly how you could do it with a custom provider but perhaps a little research will reveal it as a good option.