我在SO上问了另一个问题,有一个用户建议我做以下的事情,让我感到非常困惑:我已经在SO上读了一千遍,一个实体不应该通过服务向数据库进行保存/添加/删除调用。这是ViewModel的任务!
你怎么看?
public class School
{
private ISchoolRepository _repository;
public string Name { get; set; }
public School()
{
this._repository = IoC.Resolve<ISchoolRepository>();
}
public bool IsValid()
{
// Some kind of business logic?
if (this.Name != null)
{
return true;
}
return false;
}
public void Save()
{
if (this.isValid())
{
this._repository.Save(this)
}
}