开发者

modeling ternary relationship

I'm dealing with a database schema that is err... less than ideal. The domain deals with courses. The courses have prerequisites and related courses. The db model is somthing like this:

Courses courseid -int code -varchar

related_courses part_number varchar related_part_number varchar type int

As you might have guessed, the course and related course table is not connected vie the course pk, but instead the code column. Then the type of relationship is defined by the type column in related_course.

I would love to have a list of prerequisites and a list of related courses in my course object,but I have been unsucessfully in doing so. I'm now trying to just match the course with the related items and then filter on the type. That is not working either.

Here is my current mapping for course and course_related.

public CourseMap()
{
    Map(x => x.Code);
    HasMany(x => x.RelatedItems)
        .Access.Property()
        .PropertyRef("Code")
        .KeyColumn("Part_Id");
}

public CourseRelatedMap()
{
    References(x => x.Course, "part_id");
    HasMany(x => x.RelatedCourses)
        .Access.Property()
        .KeyColumn("part_related_id");
        //.PropertyRef("part_related_id");
}

When I try to query for the related courses, this is generating the correct sql for me:

SELECT relatedite0_.Part_Id         as Part2_1_,
       relatedite0_.CourseRelatedId as CourseRe1_1_,
       relatedite0_.CourseRelatedId as CourseRe1_12_0_,
       relatedite0_.part_id         as part2_12_0_,
       relatedite0_.Type            as Type12_0_
FROM   OCT_Course_Related relatedite0_
WHERE  relatedite0_.Part_Id = '1632LGEE-ILT' /* @p0 */

But NH is throwi开发者_如何学Cng an error trying to convert a string to int, so I'm guessing that it's trying to convert relatedite0_.Part_Id = '1632LGEE-ILT' /* @p0 */ to an integer.

Any help with this would be greatly appreciated,


Try mapping Identity properties to your entities. For CourseMap Something like this

Id(x => x.Id).Column("courseid")

I don't know if this will do it as I'm not sure I fully understood your model

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜