Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I model non-matching Foreign Keys
    text
    copied!<p>I'm trying to use EF to model an existing SQL database. The DB is multi-tenant by having a clientID column in every single table (I cannot change this). I have table structure like the following.</p> <p>Table 'ItemID' columns:</p> <pre><code>ClientID (pk) ItemID (pk) ItemName </code></pre> <p>Table 'Items' columns:</p> <pre><code>ClientID (PK) ItemID (PK) [FK to ItemID.ItemID] Version (PK) ItemAttribute1 ItemAttribute2 ItemAttribute3 </code></pre> <p>The DB is designed to store previous versions (rows) of the 'Item' object, hence the 'Version' column and PK.</p> <p>I am new to the EF and trying to adopt it for my project. However, it seems that EF cannot handle this situation very well. I am open to all ideas including using stored procedures or views instead of access tables directly from EF. What about getting rid of the PKs and using 'independant' relations instead?</p> <p>One specific problem I ran into is that EF (at least the designer) requires all PKs in one table be mapped to all PK columns in any related table. This does not make sense to me, as the example I've given will never work given that constraint. I am trying to make <code>Items</code> inherit from <code>ItemID</code>. The error I get is:</p> <blockquote> <p>Error 3003: Problem in mapping fragments starting at line 170:All the key properties (ItemID.ClientID, ItemID.ItemID) of the EntitySet ItemID must be mapped to all the key properties (Items.ClientID, Items.ItemID, Items.Version) of table Items.</p> </blockquote> <p>I have been looking up all I can find on this topic and nothing has answered these questions for me. I appreciate any help. Thanks.</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