Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate: Composite key many-to-one mapping: Can't resolve property (foreign key component)
    primarykey
    data
    text
    <p>I hope anyone can help. I have to develop up against this third party database and I am kind of stuck with their crappy design. Still, I want to use NHibernate so I will have to jump through hoops. </p> <p>Simplified, there is this "Event" table that has a relation a "Transportation" table. The transportation table has a composite primary key composed of the field "ID" and "FK_EventID", the latter of course referring back to the Event-record. Each event points to one distinct record in the transportation table, so it is a one-to-one relation really. Both fields are Guids BTW. </p> <p>Attempting to map this out, this is how I created the classes (leaving out other data fields for simplicity's sake): </p> <pre><code> public class FcoEvent : IFcoObject { public virtual Guid ID { get; set; } //public virtual Guid FK_TransportationID { get; set; } //ignore public virtual FcoTransportation Transportation { get; set; } </code></pre> <p>And: </p> <pre><code>[Serializable] public class FcoTransportation : IFcoObject { #region Members public virtual Guid ID { get; set; } public virtual Guid FK_EventID { get; set; } </code></pre> <p>In the mapping files I am attempting this (note that I am using many-to-one): </p> <pre><code> &lt;class name="FcoLib.FcoEvent, FcoLib" table="FCO_Event"&gt; &lt;id name="ID" column="ID"&gt; &lt;generator class="guid" /&gt; &lt;/id&gt; &lt;many-to-one name="Transportation" not-found="ignore" cascade="save-update" class="FcoLib.FcoTransportation, FcoLib"&gt; &lt;column name="FK_TransportationID" /&gt; &lt;column name="ID" /&gt; &lt;/many-to-one&gt; </code></pre> <p>And: </p> <pre><code> &lt;class name="FcoLib.FcoTransportation, FcoLib" table="FCO_Transportation"&gt; &lt;composite-id&gt; &lt;key-property name="ID" /&gt; &lt;key-property name="FK_EventID" /&gt; &lt;/composite-id&gt; </code></pre> <p>When I try to run this, I get the following exception message: </p> <p>NHibernate.QueryException: could not resolve property: FK_TransportationID of: FcoLib.FcoEvent</p> <p>My first hunch was that there may be a spelling error in the field name, but that didn't hold. So now I am completely puzzled and don't know how to proceed. Any help is greatly appreciated. Thnx. </p> <hr> <p><strong>Update</strong></p> <p>I think I found the source of the error. I had not looked there yet, because I assumed it was a mapping error, but apparently it is a querying error. It happens where I do the query:</p> <pre><code>fcoEvents = session.CreateCriteria(typeof(FcoEvent)) .Add(Restrictions.Eq("ID", eventId)) .Add(Restrictions.Eq("FK_TransportationID", transportId)) .List&lt;FcoEvent&gt;(); </code></pre> <p>I will look further into this, but obviously I need to query this in a different way... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload