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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:49:49+00:00 2026-06-09T10:49:49+00:00

I’m trying to use ASP MVC 4 and Entity Framework 4 to create pretty

  • 0

I’m trying to use ASP MVC 4 and Entity Framework 4 to create pretty simple web site.
I need to use the migration feature because I will deploy the application to shared hosting (GoDaddy) and I don’t want to manually change tables on each change.

What is the correct way to model one-to-many relations? Using the other entity type or the other entity’s primary key type?

When I use the other entity type, which is preferred because it keeps the model cleaner, the migration tools worked but the scaffolding of ASP MVC did not. Even when I’ve manually add drop down to select the other entity ASP MVC did not parse the request right and did not set the other entity property.

This is the two options:

Option1: Use other entity type.

 public class Tenant {
    [Key]
    public string TenantID { get; set; }
    public string Name { get; set; }
  }

  public class Survey {
    [Key]
    public string SurveyID { get; set; }

    [Required]
    public Tenant Tenant { get; set; }

    [Required]
    [StringLength(100, MinimumLength=5)]
    public string Title { get; set; }

    [Required]
    public DateTime CreatedAt { get; set; }
  }

Option 2: use primary key type.

  public class Tenant {
    [Key]
    public string TenantID { get; set; }
    public string Name { get; set; }
  }

  public class Survey {
    [Key]
    public string SurveyID { get; set; }

    [Required]
    public string TenantID { get; set; }

    [Required]
    [StringLength(100, MinimumLength=5)]
    public string Title { get; set; }

    [Required]
    public DateTime CreatedAt { get; set; }
  }

I’ve create MVC controller with scaffolding for the Survey entity in my ASP MVC 4 project. It create the CRUD controller and views. In the view it did not put any field for the Tenant.
After I’ve add it myself the method Create(Tenant tenant) was called but the Tenant field that was sent by the HTML form did not get parsed by MVC and did not set the Tenant field of the Survey entity.

Ido

  • 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-09T10:49:51+00:00Added an answer on June 9, 2026 at 10:49 am

    I’ve found this series of posts which explain how to make EF models so that they will work with both EF and ASP MVC.
    The idea is to have both “plain” reference type and strong reference type.

    public class Team
    {
        public int TeamId { get; set; }
        // ... other Team properties go here
    
        // Each Team has an optional "next opponent" which is another Team
        public int? NextOpponentId { get; set; }
        [ForeignKey("NextOpponentId")] public virtual Team NextOpponent { get; set; }
    
        // Each Team also has a required Manager and Administrator, both of which are people
        public int ManagerId { get; set; }
        public int AdministratorId { get; set; }
        [ForeignKey("ManagerId")] public virtual Person Manager { get; set; }
        [ForeignKey("AdministratorId")] public virtual Person Administrator { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a

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.