Fluent Nhibernate:映射问题
我对 Fluent Nhibernate 非常陌生。我陷入了一种情况。 请查找以下详细信息。
我们的表结构就像
表学生 { Student_Id, Name}
表学校 { School_Id, 名称}
表 LinkTable { School_Id, Student_Id}
LinkTable 仅包含学生和学校的 id。 [复合键]
关系就像 1) 一名学生可以属于 0 或 1 所学校。 2) 一所学校可以容纳许多学生。
谁能告诉我如何为每个文件完成映射?
或者让 mw 知道以下映射文件中有什么问题
现在,它给我错误,在 SchoolStudent 上找不到学生属性。
public Student()
{
Id(x => x.Id);
Map(x => x.Name);
HasOne(x => x.SchoolStudent).PropertyRef(r => r.Student);
}
public School()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.SchoolStudent).KeyColumn("School_Id").Inverse().Cascade.AllDeleteOrphan();
}
public SchoolStudent()
{
CompositeId().KeyReference(x => x.School, "School_Id")
.KeyReference(x => x.Student, "Student_Id");
}
谢谢, 马赫什
I am very much new to Fluent Nhibernate. I am stuck with the one situation.
Please find bellow details about it.
Our table structure is like as
Table Student { Student_Id, Name}
Table School { School_Id, Name}
Table LinkTable { School_Id, Student_Id}
LinkTable contains only id of the Student and School. [Composite Key]
Relation is like
1) One student can be part of 0 or 1 School.
2) One School can contains many students.
Can anyone please let me know how the mapping will be done for each file?
or let mw know what is wrong in following mapping files
Right now, it is giving me error that Student Property is not found on SchoolStudent.
public Student()
{
Id(x => x.Id);
Map(x => x.Name);
HasOne(x => x.SchoolStudent).PropertyRef(r => r.Student);
}
public School()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.SchoolStudent).KeyColumn("School_Id").Inverse().Cascade.AllDeleteOrphan();
}
public SchoolStudent()
{
CompositeId().KeyReference(x => x.School, "School_Id")
.KeyReference(x => x.Student, "Student_Id");
}
Thanks,
Mahesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会将其重写为如下内容:
Student.cs
School.cs
StudentMap.cs
SchoolMap.cs >
I would re-write it to something like this:
Student.cs
School.cs
StudentMap.cs
SchoolMap.cs
如果一个学生只能与 0 或 1 所学校关联,那么您可以考虑删除 LinkTable 和 SchoolStudent 类,而只将 School_Id 添加到 Student 表,并在 Student 类中添加对 School 的引用。
那么你的映射就像:
If a student can only be associated with 0 or 1 schools, then you might consider dropping the LinkTable and the SchoolStudent class and just add School_Id to the Student table and a reference to School in the Student class.
Then your mappings are like: