开发者

Peculiar scenario for loading child objects using nHibernate

I've got a "weird" scenario in an app I'm writting, and trying to get to grips on ow I can implement using nHibernate.

The scenario goes like this ... there is a Test. A Test is made up of a series of Testlets ( a Testlet is a set of pre-defined questions, with metadata ... ).

The thing ... while I'm running the test, the tes开发者_高级运维tlets that make it up are randomly selected from the database, according to the characteristics of the Test ( it's Level and type that is ... ).

What all this implies is that in the Testlet table in my DB, there shouldn't be a FK to the Test table. I was thinking that a custom in my pointing to a stored proc would do the job - however, when I export my mapping hbms schema to an empty DB, it still creates foreign keys in my Testlet table.

Here's my mapping for Test:

<class name="Test">
    <id name="UID">
      <generator class="guid" />
    </id>
    <property name="Type" />
    <property name="Description" />

    <bag name="Items" generic="true" inverse="false">
      <key column="UID"/>
      <one-to-many class="Testlet"/>
      <loader query-ref="loadTestletByTestID"/>
    </bag>
  </class>

<sql-query name="loadTestletByTestID">
    <load-collection alias="items" role ="Test.Items"/>
    exec [TestletByTestID] ?
  </sql-query>

Is there a way to get around that auto-created foreign key?

Thanks a lot, Angel


Why not just remove the Items from the mapping, and call a query to load random items and assign them after loading the Test? Then you wouldn't even need a stored procedure.

If it is really important to load it automatically, without code after loading the Test, you could put this code into an NHibernate even. Then it is executed whenever a Test is loaded. But actually, I doubt that it is worth the effort.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜