我想我没有看过这样的例子,但是我也没有读过任何明确指出不应这样做的地方。例如,假设我有一些用户模型,其中包含诸如姓氏等的常用信息:
public class UserModel
{
private int userID;
public int UserID
{
get { return userID; }
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleInitial { get; set; }
...
}
如果我严格遵循MVVM模式,是否可以使用其他模型列表,例如
public class UserModel
{
...
public List<SomeOtherModel> SomeList { get; set; }
}
还是模型应该只有简单的类型?
最佳答案
很简单,是的。
在进行MVVM时,您需要稍微改变一下观点。 “模型”的定义与MVC不同,而是包含 View 和 View 模型中不是的所有内容。这意味着“模型”是数据实体(即POCO),包括任何服务或 Controller ,包括业务逻辑等:
Model
The model in MVVM is an implementation of the application's domain model that includes a data model along with business and validation logic. Examples of model objects include repositories, business objects, data transfer objects (DTOs), Plain Old CLR Objects (POCOs), and generated entity and proxy objects.
引用自MSDN文章The MVVM Pattern
因此,现在您已经改变了看法,如果您的问题变成POCO(DTO)是否应包含其他POCO ?,那么答案仍然是。
关于c# - 在MVVM设计模式中,模型应该包含其他模型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49484081/