我有三张桌子(学校 - 班级 - 学生),我制作如下的模型
class School
{
private int _School_ID; // School Primary Key
public int School_ID
{ get { return _School_ID; } set { _School_ID = value; } }
public string _School_Name;
private string School_Name
{ get { return _School_Name; } set { _School_Name = value; } }
}
class Class
{
private int _Class_ID; // Class Primary Key
public int Class_ID
{ get { return _Class_ID; } set { _Class_ID = value; } }
public string _Class_Name;
private string Class_Name
{ get { return _Class_Name; } set { _Class_Name = value; } }
private int _School_ID; // School Foreign Key
public int School_ID
{ get { return _School_ID; } set { _School_ID = value; } }
}
class Student
{
private int _Student_ID; // Student Primary Key
public int Student_ID
{ get { return _Student_ID; } set { _Student_ID = value; } }
public string _Student_Name;
private string Student_Name
{ get { return _Student_Name; } set { _Student_Name = value; } }
private int _Class_ID; // Class Foreign Key
public int Class_ID
{ get { return _Class_ID; } set { _Class_ID = value; } }
}
问题是:
======================
1 - 放学生ID
2 - 学生(1).Class.School
3 - 返回学校编号
答案 0 :(得分:0)
此类与父/子相关的类通常具有指向“父”的指针,以便于在对象树中向上/向下导航。
即。
class Student
{
public Class Parent {get;set;}
public string Name {get;set;}
...
}
旁注:您在示例中显示的内容看起来像DTO(数据传输对象),它通常不会暴露在与数据库/其他存储对话的最内层之外。其他图层上的对象不会公开像DB私钥/ ID这样的内部细节,而是有用的属性(如Name
,Grade
,...)。