背景:最后一年的项目 - 使用 Mvc 4 创建 Web 应用程序。
场景:在我的应用程序中,用户应该能够选择多个首选项并对每个首选项应用优先权重。然后,这些首选项应存储在列表中,稍后用于其他与问题无关的任务。
以下是首选项的定义方式,首选项的实例成为首选项,以及我认为应该如何存储它们:
偏好选项:
public enum Weighting { One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten }
public class PreferenceOption<T>
{
public T PreferenceOptionSelected { get; set; }
public Weighting Weighting { get; set; }
}
偏好选项:
public class PreferenceOptions
{
PreferenceOption<bool> WantsHouse = new PreferenceOption<bool>() { PreferenceOptionSelected = false, Weighting = Weighting.One };
// ... could be up to 15/20 options
}
用户偏好:
public class UserPreferences
{
public List<PreferenceOptions> UserPreferences { get; set; }
}
所以我希望模型UserPreferences
能够持久地存储用户选择的所有偏好。假设如果有十个偏好,每个偏好是否会是UserPreferences
表中的一行,并且对于该用户的每一行,一列UserID
(比如 1)将是 1?
UserID | WantsHouse | OtherOption | OtherOption |
--------------------------------------------------
1 | ??? | ??? | ???
既然WantsHouse
有一个 bool 和一个 emum 值,这两者是如何存储的?
列表是存储这些的最佳方式吗?首先使用代码似乎是正确的方法 - 但列表不能连续存储 - 对吗?
最后,上面描述的其他模型(PreferenceOption
和PreferenceOptions
)是否需要持续存在?它们仅存在于内存中就足够了吗?它们的目的只是为了方便用户选择值,然后将其存储在UserPreferences
.
感谢所有帮助和反馈。