到有序列表保存到数据库中,同时保持排序的最佳方法 [英] Best way to save a ordered List to the Database while keeping the ordering
问题描述
我想知道如果任何人有一个很好的解决了我在过去几年中遇到了无数次的问题。
I was wondering if anyone has a good solution to a problem I've encountered numerous times during the last years.
我有一个购物车和我的客户明确要求,它的顺序是显著。所以,我需要坚持的以数据库。
I have a shopping cart and my customer explicitly requests that it's order is significant. So I need to persist the order to the DB.
最显而易见的方法是简单地插入一些OrderField在那里我会数0分配给N和排序这种方式。
The obvious way would be to simply insert some OrderField where I would assign the number 0 to N and sort it that way.
但这样做会使重新排序更难,我莫名其妙地觉得,这个解决方案是有点脆弱,有一天会回来看我。
But doing so would make reordering harder and I somehow feel that this solution is kinda fragile and will come back at me some day.
(我使用C#3,5与NHibernate和SQL Server 2005)
(I use C# 3,5 with NHibernate and SQL Server 2005)
感谢您
推荐答案
FWIW,我觉得你建议的方式(即在提交订单到数据库)是个不错的解决您的问题。我也觉得这可能是最安全/最可靠的方法。
FWIW, I think the way you suggest (i.e. committing the order to the database) is not a bad solution to your problem. I also think it's probably the safest/most reliable way.
这篇关于到有序列表保存到数据库中,同时保持排序的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!