Disclaimer: This may be more of an NH question first to figure out the
XML/potential before working it through FNH, but none-the-less. (^_^)

Class model: http://is.gd/ccnA

I'm trying to figure out how to map the relationship that a Teacher
has a collection of Students; however, the relationship IDs are parsed
from another table.  I've managed to get it working, but now I need
distincts.

HasManyToMany<Student>(x => x.Students)
                .WithTableName("roster_mv")  // maps student>teacher
relationships
                .WithParentKeyColumn("teacher_id") // "teacherId"
                .WithChildKeyColumn("pupil_number") // "studentId"
                .LazyLoad();

The (relevant) generated XML mapping file is as follows:

[*clip*]

<class name="Teacher" table="teacher_lkup_mv" xmlns="urn:nhibernate-
mapping-2.2">
<id name="Id" column="Id" type="Int32">
  <generator class="identity" />
</id>

<bag name="Students" lazy="true" table="roster_mv">
<key column="teacher_id" />
<many-to-many column="pupil_number" class="Domain.Student" />
</bag>
<many-to-one fetch="join" lazy="proxy" name="School"
column="SchoolId" />
</class>

[*clip*]

The requested rows ARE distinct; however, there are additional rows in
the view that break that distinction (e.g. a student takes multiple
courses from one teacher, so they'd have as many rows as per courses);
but those are outside the scope of building the object.

Now, if I didn't want this to be a relationship/property of the
Teacher object, I could do this through an extension method or
something:

    public static class TeacherExtensions
    {
        public static IList<Student> GetDistinctStudents(this Teacher
teacher)
        {
            return teacher.Students.Distinct().ToList() as
List<Student>;
        }
    }

But I'm not wanting to toss the distinction work back on the calling
system--much prefer it distinct it on the database call.

Ideas or suggestions?  Thanks in advance!

-dl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to