使用动态数据实体限制 nvarchar 列的值

发布于 2024-09-16 18:19:21 字数 331 浏览 3 评论 0原文

我正在使用 ASP.NET 动态数据实体项目为我的数据库生成 Web 应用程序。我想知道限制列允许值的最简单方法是什么,而不更改数据库结构以使该列成为外键或以任何方式修改数据库。

例如。我有一个名为 Assets 的表,其中有一个 TypeOfAsset 的 nvarchar(50) 列。例如,我想将资产类型限制为“打印机”、“台式机”或“笔记本电脑”。我希望所有搜索和创建模板自动使用此列的下拉列表而不是文本字段。

我是否必须创建自定义模板并使用 UIHint 属性?我可以在元数据中使用其他属性吗?或者有没有办法限制 LinqToSql 中的值,以便就动态数据实体而言,它自然使用 Dropdownlists?

I am using ASP.NET Dynamic Data Entities project to generate a web application for my database. I was wondering what is the easiest way to restrict the allowed values for a column without changing the database structure to make that column a foreign key or modifying the database in any way.

For example. I have a table called Assets which has an nvarchar(50) column of TypeOfAsset. I want to restrict the type of asset to "Printer", "Desktop" or "Laptop" for example. I would like all the search and create templates to automatically use Dropdown lists for this column rather than a text field.

Would I have to create custom templates and use the UIHint attirbute? Is there some other attribute I can use in the metadata? or is there a way to restrict the values in LinqToSql, so that as far as Dynamic Data Entities are concerned, it naturally uses Dropdownlists?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

秋日私语 2024-09-23 18:19:21

在这里找到了答案。
http://csharpbits.notaclue.net/2009/ 07/dynamic-data-custom-field-template.html

基本上创建自定义属性和自定义字段模板。该属性指定要显示的受限值,字段模板有一个下拉列表,该列表将填充属性中指定的逗号分隔值。

Found the answer here.
http://csharpbits.notaclue.net/2009/07/dynamic-data-custom-field-template.html

Basically creating a custom attribute and a custom field template. The attribute specifies the restricted values to display and the field template has a dropdownlist that will be populated with the comma delimited values specified in the attribute.

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