使用指定模式是否正確使用導航屬性?帶導航屬性的指定模式
我有如下方面:
當我添加一個學生,我需要驗證的地址。
學生類:
public class Student {
public string Name { get; set; }
public DateTime Birth { get; set; }
//...
public virtual ICollection<StudentAddress> StudentAdresses { get; set; }
}
StudentAddress類:
public class StudentAdress{
public int Id { get; set;}
public string Street { get; set; }
//...
}
在我的學生服務(DDD):
服務:
public void AddStudent(Student student)
{
// code
var studentValidation = new StudentValidation().Validate(student); // Student Validation has a set of specifications that will populate a validation result object and that I'll retrieve it by Domain Controller Notification (MVC)
// code
}
PS:學生驗證了一套規範,將填充驗證結果對象,我會通過域控制器通知(MVC)
回到問題檢索...
我可以在哪裏放置我的學生地址班級規格?
我想到了將它們放入StudentValidation類中的可能性,並且使用Navigation屬性可以驗證每個地址。我不知道這是否正確。這將是一種橫向驗證。
爲什麼StudentAddress是一個實體?它應該是一個價值對象。 –
我認爲我對這個問題的回答可能會指導你在正確的方向關於UI驗證與域驗證:http://stackoverflow.com/questions/28395176/should-i-abstract-the-validation-framework-from-domain-圖層/ 28397201#28397201 – plalx
Constantin,StudentAddress是我DB上的表格。它具有身份,我認爲價值對象是特定實體的一組屬性。 –