Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The error is correct. I'm guessing that you are using <code>SchemaExport</code> to generate your tables based on the NHibernate mappings, since the error you are receiving sounds like it would occur during the creation of your tables and foreign keys. <code>SchemaExport</code> would produce tables similar to the following (please note the explanations scattered throughout the code):</p> <pre><code>CREATE TABLE LocationSearchView ( LocationId int NOT NULL, ContentProviderId int NOT NULL, CategoryId int NOT NULL, /* ...other columns... */ /* Note: Generated from LocationSearchView's "composite-id" element. */ PRIMARY KEY (LocationId, ContentProviderId, CategoryId) ); /* Note: Table for the "Event" class. */ CREATE TABLE VolatileEventContent ( LocationId int NOT NULL, ContentProviderId int NOT NULL, /* ...other columns... */ /* Note: Generated from Event's "composite-id" element. */ PRIMARY KEY (LocationId, ContentProviderId), /* Note: Generated from the "key" element of LocationSearchView's Events bag. */ FOREIGN KEY (LocationId, ContentProviderId) REFERENCES LocationSearchView (LocationId, ContentProviderId) ); </code></pre> <p>... hence the error. A foreign key must point to a complete primary or unique key - not just part of a primary key. The whole key is 3 columns, not 2. Why would NHibernate use those columns for the foreign key? Because of the <code>&lt;key&gt;</code> element of <code>LocationSearchView</code>'s <code>Events</code> bag. <code>&lt;key&gt;</code> specifies which columns from the <em>child</em> point back to the <em>parent</em>.</p> <p>Let's consider what might happen when you (or NHibernate) try to select from these tables. Assume the following data:</p> <pre> TABLE LocationSearchView LocationId ContentProviderId CategoryId ========== ================= ========== 1 3 5 1 3 6 1 4 5 1 4 6 2 3 5 2 3 6 2 4 5 2 4 6 </pre> <pre> TABLE VolatileEventContent LocationId ContentProviderId ========== ================= 1 3 1 4 2 3 2 4 </pre> <p>It is not possible for "one" <code>LocationSearchView</code> to have "many" <code>Event</code>s. Rather, it should be the other way around. Given these tables, there is really a one-to-many relationship from <code>Event</code> to <code>LocationSearchView</code>.</p> <p>I don't know what the correct solution to this problem is, because I don't know what you are trying to accomplish, but hopefully this helps to illuminate what exactly the problem is.</p>
 

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