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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:05:55+00:00 2026-06-17T23:05:55+00:00

This is my first Question on stackoverflow, I hope I am doing it right

  • 0

This is my first Question on stackoverflow, I hope I am doing it right 😉 The search doesn’t provided any hint to my current problem. I am new to ASP.NET MVC 4.

I’ve set up a new ASP.NET MVC 4 Project using Razor-HTML-Engine. I created two Models:

Model Client

[Table("Clients")]
public class Client
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public string ContactName { get; set; }

    public ICollection<License> Licenses { get; set; }
}

Model License

[Table("Licenses")]
public class License
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public string SerialNumber { get; set; }

    public ICollection<ActivationHistory> ActivationHistory { get; set; }
}

I read that I will have to make a new Class deriving from DbContext in Order to get this working properly:

public class ClientDbContext : DbContext
{
    public DbSet<Client> Clients { get; set; }
    public DbSet<License> Licenses { get; set; }
}

In my opinion this gives me:

  • two Tables with PrimaryKeys and the association between the Tables (1:N)
  • the ability to create a Client Object and use Client.Licenses.Add() to add a new Element to the Table after using db.SaveChanges()
  • a Client with all Licenses using var t = db.Clients.Single(a => a.Id == 1);

  • Am I right so far?

I now added sample data to the Client:

// Get Context
var c = new ClientDbContext();

// Create new License
var n1 = new License();
// Testdata
n1.SerialNumber = "12345";

// Get test Client
var test = c.Clients.Single(v => v.ContactName.Contains("Testclient"));

// Add test License to Client
test.Licenses.Add(n1);

// Save Changes
c.SaveChanges()

Checking the Database, a new Row in the License-Table has been added. There is a foreign Key Client_Id pointing to the correct client Testclient

But if I try to show the information from License on the View, there are no Entries at all:

                 foreach (var item in Model.Licenses)
                 {
                     @Html.DisplayFor(modelItem => item.SerialNumber)
                 }

I am using the default Controller-Method:

    public ActionResult Details(int id = 0)
    {
        Client client = db.Clients.Find(id);
        if (client == null)
        {
            return HttpNotFound();
        }

        return View(client);
    }

Can anyone please give me a hint what I am doing wrong?

Thank you very much!

  • 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-17T23:05:56+00:00Added an answer on June 17, 2026 at 11:05 pm

    You have to mark your navigation properties(Licenses) as virtual.

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

Sidebar

Related Questions

Im a new user in stackoverflow and this is my first question hope i
I'm fairly new to Objective-C, and this is my first question on StackOverflow. Please
I'm new to ruby and this is my first stackoverflow question (although I've used
Since this is my first question here on stackoverflow I hope my question is
This is my first post on stackoverflow, I hope one of many! My question
This is my first question ever at stackoverflow, hope I make sense out of
This is my first question here on stackoverflow, so I hope that I am
This is actually my very first question on Stackoverflow. I hope its not the
My first stackoverflow question, hope I do it right.. I'm trying to build a
First time posting in Stack Overflow, hope I'm doing this right. I'm writing an

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.