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 4535960
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:28:17+00:00 2026-05-21T14:28:17+00:00

Consider the following example model: Person has 0..1 User User has 1 Person Attempt

  • 0

Consider the following example model:

  • Person has 0..1 User
  • User has 1 Person

Attempt 1:

  • I dragged an association from Person to User on the model designer.
  • I fixed the cardinality to meet my needs (the default is 1xN)
  • I generated the DDL from model

Problem:

  • The output User table has a Person_id column with no unique constraint. That is, it’s not a 1×1 relationship as many Users can reference the same Person. There must be something wrong here

Attempt 2:

  • Dragged an association from Person to User on the model designer.
  • Fixed the cardinality to meet my needs (the default is 1xN)
  • Selected the association and clicked the Referential Constraint button on the properties window to edit the association
  • Selected Person to be the Principal and User to be the Dependent type
  • Chosen the Principal Key to be Id and the Dependent Property to be also Id (I’ve read somewhere that I should use the same key for both types)

Problem:

I run this code:

using (var context = new Locadora())
{
    User user = new User ();
    user.PasswordHash = "hash";
    user.Pessoa = new Person();
    user.Pessoa.Nome = "André";

    context.Usuários.AddObject(user);

    context.SaveChanges();
}
  • SaveChanges triggers this exception:

A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: ‘Id’

So I am out of choices now. I don’t know how to implement a 1×1 neither a 1×0..1 relationship in Entity Framework.

How do I do that?

  • 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-21T14:28:18+00:00Added an answer on May 21, 2026 at 2:28 pm

    The first attempt can’t work because current EF version doesn’t support Unique keys at all. Second approach doesn’t work because you dependent entity can’t have autogenerated key = StoreGeneratedPattern must be set to None.

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

Sidebar

Related Questions

The problem is best explained by example, consider the following two models: class Topping(models.Model):
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example. It consists of two header files, declaring two different namespaces:
Consider the following radio button example. <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml> <mx:Script> <![CDATA[ private
Consider the following 2 queries: select tblA.a,tblA.b,tblA.c,tblA.d from tblA where tblA.a not in (select
Consider the following Django models: class Host(models.Model): # This is the hostname only name
Consider a typical social networking website, which has more or less the following models:
Consider the following example: var funcToCall = function() {...}.bind(importantScope); // some time later var
Consider the following example code: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html I can do scrollwheel: false on a mapOptions
Is there any portable way of doing branch prediction hints? Consider the following example:

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.