ViewModel与域模型字段差异

时间:2015-09-01 16:40:45

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

我几天前在ASP.Net网页上使用了Entity Framework设计器。我现在首先切换代码和MVC应用程序。我已经有了模型代码(由VS模型设计师创建),所以我正在使用它们。他们已经有这样的关系(导航)代码:

public class User
{
    [Key]
    public string UserUsername { get; set; }
    public string UserPassword { get; set; }
    public decimal UserType { get; set; }
    public decimal BranchId { get; set; }
    public virtual Branch Branch { get; set; }
}

正如您所看到的,用户分支之间存在关联。它现在正在工作但是在切换MVC之后我了解到我需要使用ViewModels而不是我首先创建的模型,这就是问题,我肯定会将公共虚拟分支分支包含到我的ViewModel中但是我应该在我的原始模型(域模型)中保留该行?因为我在保存时不会使用分支,所以我只需要BranchId。

我很困惑,为我做事情需要花费更多时间(现在)。

由于

0 个答案:

没有答案
相关问题