c# - 如何在 View 模型中使用域模型关系?

标签 c# asp.net-mvc entity-framework

我正在使用 View 模型来将域模型与数据表示分开,但我不知道如何使用域模型中存在的数据库表关系。 例如这个域模型类应该如何在 View 模型中使用?在此示例中,CurrencyDictionary 是具有设置表外键的表。

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; }
}

最佳答案

对于任何给定的相关域模型,您都有相应的 View 模型,因此您的 Settings View 模型将包含相应的 CurrencyDictionary View 模型,例如:

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

关于c# - 如何在 View 模型中使用域模型关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30838718/

相关文章:

c# - 该接口(interface)是否已存在于标准 .NET 库中?

c# - 检查linq中的最后一项

c# - 删除相关实体时出现“集合已修改”错误

c# - ProjectTo 不识别无参数构造函数

c# - 数据库已创建,未添加新表

c# - 一个上下文引用 LINQ 查询抛出多个引用异常 - BUG?

c# - 不在 asp.net core 中的 HttpRequestMessage 和 HttpResponseMessage 上调用 Dispose

sql - 连接表并投影到新模型中

c# - 如何删除 dbo.AspNetUserClaims 和 dbo.AspNetUserLogins 表(IdentityUserClaim 和 IdentityUserLogin 实体)?

c# - MVC 表单上的多个按钮 - 在操作 Controller 中获取项目 ID