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

  • Home
  • SEARCH
  • 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 8861439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:29:34+00:00 2026-06-14T15:29:34+00:00

I have two tables CREATE TABLE Company ( Id uniqueidentifier primary key not null,

  • 0

I have two tables

CREATE TABLE Company (
    Id uniqueidentifier primary key not null, 
    CompanyName nvarchar(100) not null)
GO

CREATE TABLE Feature (
    Id uniqueidentifier primary key not null, 
    CompanyId uniqueidentifier not null, 
    Feature1 bit not null, 
    Feature2 bit not null)
GO

How to make one to one relation by CompanyId field on database and EF Code First side with configuration files

The classes:

    public class Company
{
    private Guid id = Guid.NewGuid();

    public virtual Guid Id
    {
        get { return id; }
        set { id = value; }
    }

    public virtual string CompanyName { get; set; }
}

public class Feature
{
    private Guid id = Guid.NewGuid();

    public virtual Guid Id
    {
        get { return id; }

        set { id = value; }
    }

    public virtual Company Company { get; set; }

    public virtual bool Feature1 { get; set; }

    public virtual bool Feature2 { get; set; }
}
  • 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-06-14T15:29:35+00:00Added an answer on June 14, 2026 at 3:29 pm

    You cannot make a real one-to-one relation in EF with these tables because it requires unique index on CompanyId column and EF doesn’t support unique indices yet. Currently the only way to get a real one-to-one relation is to use primary key of dependent table (in your case Feature.Id) as foreign key to principal table.

    You can cheat. Just use it as one-to-many (Company can have many features) and if you have unique index in the database you will receive exception if another feature tries to associate with already used company.

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

Sidebar

Related Questions

I have two SQL statements: CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have two tables like, CREATE TABLE [dbo].[entry] ( [id] [int] NULL, [service] [int]
I have two tables: codes_tags and popular_tags. codes_tags CREATE TABLE `codes_tags` ( `code_id` int(11)
I have two tables: entitytype and project . Here are the create table statements:
I have two tables A and B as defined bellow. create table A (
I am using luasql. I have two tables of this type: IPINFO CREATE TABLE
I have one query that I have below two tables .. CREATE table EMPLOYEE
In my dbsql file, I have two CREATE TABLES the first works and the
I have created two tables & inserted values as shown below . Table 1

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.