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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:34:02+00:00 2026-05-28T00:34:02+00:00

EF Code First – Model I have 2 classes: public class Alias { public

  • 0

EF Code First – Model

I have 2 classes:

public class Alias
{
    public int id { set; get; }
    public string Name { set; get; }
    public ICollection<Tweet> Tweets { set; get; }
}

public class Tweet
{
   public int id {set;get;}
   public Alias Author { set; get; }
}

It creates a Author_Id (FK) in the Tweet class. Okay makes sense, because it has a relationship between two models. But how come it doesn’t create Tweet_Id (FK) in the Alias class? or is it because I am using ICollection? why it creates a FK in Tweet class and not vice versa?

What keyword tells the EF to create a FK in its model

Also I tried the below code and it fails….

public class Alias
{
    public int id { set; get; }
    public string Name { set; get; }
    public Tweet Tweets { set; get; }
}

public class Tweet
{
   public int id {set;get;}
   public Alias Author { set; get; }
}

I am trying to understand how the model works, how and when it creates a FK? … please provide me a brief explanation… Thank you in advance!

  • 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-28T00:34:02+00:00Added an answer on May 28, 2026 at 12:34 am

    SQL doesn’t need a foreign key on both tables. There isn’t a concept of a direction the way there is in C#.

    The Tweet table needs an id to say which Alias it’s connected to. From that you can query all tweets that were made by that alias pretty easily.

    If there were a Tweet_Id on the Alias table, what would be set to once there was a second tweet made by the same person?

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

Sidebar

Related Questions

The Code-First model: public class Princess { public int Id { get; set; }
I have a code first model: namespace InternetComicsDatabase.Models { public class Issue { [Key]
So strange! Please have a look the code first: public class A {} public
I am working with Entity Framework Code first. I have a simple model: public
Code first: public class ExtendedGridView : GridView { private ImageButton m_btnPrint; public ImageButton PrintButton
With EF CTP5 Code-First I am trying to map a class model which contains
I have some simple Code First classes with a Many to One relationship. If
I'm testing how code first works. Here's how I defined the Context public class
I often refactor code first by creating an inner class inside the class I'm
I have an AXIS2/JAX-WS web service using a code first implementation (yes I know,

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.