Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've tried defining the following tables: </p> <ul> <li>Orders [Id (primary, identity), ClientName, FriendlyOrderNum (unique)]</li> <li>OrderItems [Id (primary, identity), FriendlyOrderNum (unique), ItemName]</li> </ul> <p>And a foreign key mapping from OrderItems.FriendlyOrderNum (Mant) to Orders.FriendlyOrderNum (one).</p> <p>If unique non-primary keys are possible the following SSDL should work:</p> <pre><code>&lt;Schema Namespace="EfUkFk_DbModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"&gt; &lt;EntityContainer Name="EfUkFk_DbModelStoreContainer"&gt; &lt;EntitySet Name="OrderItems" EntityType="EfUkFk_DbModel.Store.OrderItems" store:Type="Tables" Schema="dbo" /&gt; &lt;EntitySet Name="Orders" EntityType="EfUkFk_DbModel.Store.Orders" store:Type="Tables" Schema="dbo" /&gt; &lt;/EntityContainer&gt; &lt;EntityType Name="OrderItems"&gt; &lt;Key&gt; &lt;PropertyRef Name="RowId" /&gt; &lt;/Key&gt; &lt;Property Name="RowId" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" /&gt; &lt;Property Name="OrderNum" Type="char" Nullable="false" MaxLength="5" /&gt; &lt;Property Name="ItemName" Type="varchar" MaxLength="100" /&gt; &lt;/EntityType&gt; &lt;!--Errors Found During Generation: warning 6035: The relationship 'FK_OrderItems_Orders' has columns that are not part of the key of the table on the primary side of the relationship. The relationship was excluded. --&gt; &lt;EntityType Name="Orders"&gt; &lt;Key&gt; &lt;PropertyRef Name="RowId" /&gt; &lt;/Key&gt; &lt;Property Name="RowId" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" /&gt; &lt;Property Name="ClientName" Type="varchar" MaxLength="100" /&gt; &lt;Property Name="OrderNum" Type="char" Nullable="false" MaxLength="5" /&gt; &lt;/EntityType&gt; &lt;!-- AsafR --&gt; &lt;Association Name="FK_OrderItems_Orders"&gt; &lt;End Role="Orders" Type="EfUkFk_DbModel.Store.Orders" Multiplicity="1"&gt; &lt;/End&gt; &lt;End Role="OrderItems" Type="EfUkFk_DbModel.Store.OrderItems" Multiplicity="*" /&gt; &lt;ReferentialConstraint&gt; &lt;Principal Role="Orders"&gt; &lt;PropertyRef Name="OrderNum" /&gt; &lt;/Principal&gt; &lt;Dependent Role="OrderItems"&gt; &lt;PropertyRef Name="OrderNum" /&gt; &lt;/Dependent&gt; &lt;/ReferentialConstraint&gt; &lt;/Association&gt; &lt;/Schema&gt;&lt;/edmx:StorageModels&gt; </code></pre> <p>It doesn't. There's also no possibility for adding more &lt;key&gt; elements in an &lt;EntityType&gt;.</p> <p>My conclusion is that non-primary unique keys are not support in EF 4. </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