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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:11:16+00:00 2026-05-23T08:11:16+00:00

So I am working on some Entity Framework Code First. I am pretty new

  • 0

So I am working on some Entity Framework Code First. I am pretty new at database relational mapping in general. I have created a generic example for my question which I will post the code for below.

The scenario is a simple poll on a forum. A user can vote on a poll by selecting an option (or perhaps multiple poll options).

Poll and Option have a one-to-many relationship.
Option and User have a many-to-many relationship.
Poll and User have a many-to-many relationship.

But the Users that Poll has will basically be compiled from the Users that Options has, since to vote on an option, you must vote on the poll and vice-versa. So basically I guess it could be described as a User/Options join table with the Options’ Polls’ primary keys tacked on. Or it could be kind of like a User/Poll join table with Option as an array of complex types or something.

Anyways I have been working with the Fluent API (DbModelBuilder), but I have yet to get something like what I am looking for. Help?

Poll.cs

public class Poll
{
  public long ID { get; private set; }
  public ICollection<Option> Options { get; set; }
  public ICollection<User> Users { get; set; }
}

Option.cs

public class Option
{
  public long ID { get; private set; }
  public long PollID { get; set; }
  public ICollection<User> Users { get; set; }
}

User.cs

public class User    {
  public long ID { get; private set; }
  public ICollection<Option> Polls { get; set; }
  public ICollection<User> Options { 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-05-23T08:11:16+00:00Added an answer on May 23, 2026 at 8:11 am

    Why do you need connection between Poll and User? That is redundant information – you can always get that data by query through Options. If you really want it introduce forth entity called Vote which will keep PollId, UserId and OptionId. Your application logic will have to ensure that valid combination of OptionId and PollId are used. Another way to solve this is creating composite key in Option consisting from OptionId and PollId. Then you will create many to many relation between User and Option. It will partially solve needs fro Poll dependency in user and it will completely remove problems with checking valid pairs of OptionId and PollId.

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

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
I have co-workers working on an Entity Framework model that changes structure (entities), over
I have been working with NHibernate, LINQ to SQL, and Entity Framework for quite
I have been working with Entity Framework 4 recently, and am slightly confused as
I'm wondering if using VS.Net 2010, I can have Entity Framework 3.5 code running
I have a .NET 4 WinForms app that uses the ADO.NET Entity Framework. Some
I'm working on some production software, using C# on the .NET framework. I really
I'm working on some code to colorize an image in Java. Basically what I'd
I'm working on some code that uses the System.Diagnostics.Trace class and I'm wondering how
I'm working on some code for a loosely coupled cluster. To achieve optimal performance

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.