开发者

Ordering in dropdown in MVC

开发者 https://www.devze.com 2023-01-04 22:18 出处:网络
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 wh

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开发者_JS百科 a view and use the ordering in the view to fill out the dropdown correctly?

Thanks in advance, Steffen Jorgensen, Denmark


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消