Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 715095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:08:54+00:00 2026-05-14T05:08:54+00:00

An existing DB schema has unique, non-primary, keys, and some foreign keys that rely

  • 0

An existing DB schema has unique, non-primary, keys, and some foreign keys that rely on them.

Is it possible to define unique keys, which are not primary keys, in Entity Framework v4? How?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:08:55+00:00Added an answer on May 14, 2026 at 5:08 am

    I’ve tried defining the following tables:

    • Orders [Id (primary, identity), ClientName, FriendlyOrderNum (unique)]
    • OrderItems [Id (primary, identity), FriendlyOrderNum (unique), ItemName]

    And a foreign key mapping from OrderItems.FriendlyOrderNum (Mant) to Orders.FriendlyOrderNum (one).

    If unique non-primary keys are possible the following SSDL should work:

    <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">
        <EntityContainer Name="EfUkFk_DbModelStoreContainer">
          <EntitySet Name="OrderItems" EntityType="EfUkFk_DbModel.Store.OrderItems" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="Orders" EntityType="EfUkFk_DbModel.Store.Orders" store:Type="Tables" Schema="dbo" />
        </EntityContainer>
        <EntityType Name="OrderItems">
          <Key>
            <PropertyRef Name="RowId" />
          </Key>
          <Property Name="RowId" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="OrderNum" Type="char" Nullable="false" MaxLength="5" />
          <Property Name="ItemName" Type="varchar" MaxLength="100" />
        </EntityType>
        <!--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.
      -->
        <EntityType Name="Orders">
          <Key>
            <PropertyRef Name="RowId" />
          </Key>
          <Property Name="RowId" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="ClientName" Type="varchar" MaxLength="100" />
          <Property Name="OrderNum" Type="char" Nullable="false" MaxLength="5" />
        </EntityType>
    
      <!-- AsafR -->
        <Association Name="FK_OrderItems_Orders">
          <End Role="Orders" Type="EfUkFk_DbModel.Store.Orders" Multiplicity="1">
          </End>
          <End Role="OrderItems" Type="EfUkFk_DbModel.Store.OrderItems" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="Orders">
              <PropertyRef Name="OrderNum" />
            </Principal>
            <Dependent Role="OrderItems">
              <PropertyRef Name="OrderNum" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema></edmx:StorageModels>
    

    It doesn’t. There’s also no possibility for adding more <key> elements in an <EntityType>.

    My conclusion is that non-primary unique keys are not support in EF 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see that EF can update a model based on an existing database schema.
I am working on some schema changes to an existing database. I backed up
Some existing web services I consume have methods that look something like this: List<Employee>
Is it possible to continue or extend an existing schema with MySQL Workbench? This
I'm currently writing a C# webservice that has to match an existing wsdl, and
Are there any good tools for visualising a pre-existing database schema? I'm using MySQL
I was trying to add the XML schema to an existing EJB project. JAXB
I know this is a task that can't be unique, but I can't seem
I've got a web app I'm building in ASP.NET that has the following security
I'm currently trying to find a way of adding some extra elements to existing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.