Discussion:
[nhusers] NHibernate : how to map a collection that requires some calculation?
Eric Chow
2018-02-09 01:26:12 UTC
Permalink
Hello,

Is it possible to using .hbm.xml to map a collection that retrieve with
some special calculation on a field?

For example, the following is some test classes and mapping .hbm.xml:

public class Student {
public virtual long StudentNo { get; set; }
public virtual int Year { get; set; }
public virtual IList<TestResult> Tests { get; set; }
}

public class TestResult {
public StudentNo { get; set; }
public DateTime TestDate { get; set; }
public int SubjectCode { get; set; }
public float Marks { get; set; }
}




<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping assembly="UDFU.Net" namespace="UDFU.Net.Model"
xmlns="urn:nhibernate-mapping-2.2">
<class name="Student" table="STUDENT" lazy="false">


<composite-id>
<key-property name="StudentNo" column="STUDENT_NO"/>
<key-property name="Year" column="YEAR"/>
</composite-id>



<bag name="Tests" table="TEST_RECORD" fetch="select" lazy="false">
<key>
<column name="STUDENT_NO"/>
</key>


<one-to-many class="TestResult" not-found="ignore"/>
</bag>



</class>

</hibernate-mapping>





The problem is that in the Student class, how can I only retrieve those
TestResults as the TestDate equals to the Year ?

The above .hbm.xml will retrieve all the TestResults, but I just want to
get the TestResults that the date were taken in the same Year in of student.

How can I define the .hbm.xml ?

Please teach me, thanks.

Eric
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...