如何在视图模型中使用域模型关系

本文关键字:模型 关系 视图 | 更新日期: 2023-09-27 17:56:18

>我正在使用视图模型来将域模型与数据表示分开,但我无法了解如何使用域模型中存在的数据库表关系。例如,这个域模型类应该如何在视图模型中使用?在这个示例货币字典中,是带有设置表的外键的表。

public partial class Settings
{
    public int Id { get; set; }
    ...List of properties...
    public int ShopCurrency { get; set; }
    public IEnumerable<SelectListItem> CurrencyList { get; set; }     
    public virtual CurrencyDictionary CurrencyDictionary { get; set; }
}

如何在视图模型中使用域模型关系

对于

任何相关的给定域模型,您都有一个相应的视图模型,因此您的Settings视图模型将包含相应的CurrencyDictionary视图模型,如下所示:

public class SettingsModel
{
    public CurrencyDictionaryModel CurrencyDictionary { get; set; }
}