MVC 中的下拉列表排序

发布于 2024-09-07 15:08:43 字数 217 浏览 0 评论 0原文

我在 MVC 视图中的下拉列表中遇到问题。下拉列表中的选项元素来自表,应按 HierarchyId 列排序。我已经创建了一个正确排序的视图,但是当我从视图创建实体并将其用于下拉列表时,排序将被忽略。

我发现 L2S 和 EF 不支持 HierarchyId 数据类型,因此这可能是问题所在 - 但必须可以创建一个视图并使用视图中的顺序来正确填写下拉列表?

提前致谢, 史蒂芬·乔根森,丹麦

I've a problem with a dropdown in a view in MVC. The option-elements in the dropdown comes from a table and should be ordered by a hierarchyId column. I've made a view which orders correctly, but when I create my entity from the view and use it for the dropdown the ordering is ignored.

I found out that hierarchyId datatype is not supported in L2S and EF, so that might be the problem - but it must be possible to make a view and use the ordering in the view to fill out the dropdown correctly?

Thanks in advance,
Steffen Jorgensen, Denmark

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

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

发布评论

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

评论(1

帝王念 2024-09-14 15:08:43

好的 - 我发现问题是什么了。事实证明,是模型的行为不正确。相反,问题是 SQL Server 2008 不允许在视图中排序,除非您在顶部放置 TOP 子句。但如果您使用 TOP 100 PERCENT,则排序将不起作用。如果我更改为 TOP 99 PERCENT 它工作正常(除了我没有得到我需要的所有行)?!我没有非常大的数据集,所以我尝试将其更改为 TOP 10000,瞧,一切都按预期进行!

我在这里找到了解决方案:
http://www.networkworld.com/community/node/34784

挖掘一下深入研究这个主题,发现 MS 已知该错误 (http://support.microsoft. com/kb/926292/)并已修复。我最好踢掉我的 DBA 并更新我们的服务器:-)

OK - I found out what the problem was. It turned out that it was the model that didn't behave correctly. Instead the problem was that SQL Server 2008 doesn't allow ordering in views unless you put a TOP clause at the top. But if you use TOP 100 PERCENT, the ordering will not work. If I changes to TOP 99 PERCENT it works fine (except that I don't get all the rows I need)?! I don't have very large dataset, so I tried to change it to TOP 10000 and Voilá everything works as expected!

I found the solution here:
http://www.networkworld.com/community/node/34784

Digging a little deeper into the subject it turns out that the bug is known by MS (http://support.microsoft.com/kb/926292/) and has been fixed. I'd better kick my DBA and get our server updated :-)

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