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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:06:03+00:00 2026-06-04T09:06:03+00:00

Actually I’m working on simple project MVC4 + EF in which I have relation

  • 0

Actually I’m working on simple project MVC4 + EF in which I have relation application-license. On application may has zero or more licenses, but every license has only one application. I’ve noticed some problem with operation edit/create new license. I past part of my code.

My entity domain definitions:

public class Application
{
    public Application()
    {
        Licenses = new List<License>();
    }

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid ApplicationID { get; set; }

    public string Name { get; set; }

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

public class License
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [HiddenInput(DisplayValue = false)]
    public Guid LicenseID { get; set; }

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

    public Version Version { get; set; }

    public Application Application { get; set; }
}

Definition one to many between application and licenses:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Application>()
        .HasMany(app => app.Licenses)
        .WithRequired()
        .Map(conf => conf.MapKey("OwnerID"))
        .WillCascadeOnDelete(false);

    modelBuilder.Entity<License>()
        .HasRequired(lic => lic.Application)
        .WithMany()
        .Map(conf => conf.MapKey("ApplicationID"))
        .WillCascadeOnDelete(false);
}

Action in License controller:

public ActionResult Create(Guid applicationID)
{
    var application = repositoryApps.Applications.FirstOrDefault(a => a.ApplicationID == applicationID);

    var license = new License {Application = application};
    application.Licenses.Add(license);

    return View("Edit", license);
}

public ActionResult Edit(License license)
{
    return View(license);
}

[HttpPost]
public ActionResult Save(License license)
{
    if(ModelState.IsValid)
    {
        repositoryLics.SaveLicense(license);
        TempData["message"] = string.Format("{0} has been saved", license.Name);

        return RedirectToAction("Index", "Application");
    }
    else
    {
        return View("Edit", license);
    }
}

Edit view for fincense:

@using (Html.BeginForm("Save", "License"))
{
    @Html.EditorForModel(Model);

    <input type="submit" value="Save" class="btn btn-primary"/>

    @Html.ActionLink("Cancel", "Index", "Application", null, new {@class = "btn"})
}

I’ve problem in situation when I’m creating new license. I’m invoking action Create and pass to it parent ApplicationID. After some preparation I’m passing license instance to Edit view in which is possible to edit new created object. In Edit view (for licenses) everything seems to be OK. I have a license with not null field Application (in which I have collection of licenses). When I submit edit form, then I’m back to action Save(License license). Unfortunately in this place property Application is equal to null, so I miss relation between new created license and parent application.

Has anybody any suggestions how can I avoid this problem? How should I store new created licenses objects? I’ll be thankful for any hints or advices.

Regards,
Grzegorz

  • 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-04T09:06:05+00:00Added an answer on June 4, 2026 at 9:06 am

    I don’t see ApplicationID property in your License class !!??

    you should add this property and add it so in the EditorTemplate maybe as hidden if you want.
    BTW add your License EditorTemplate to your question to let us know about it.

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

Sidebar

Related Questions

Actually i'm working in a project which need print a test page to a
Actually I am working on the Couchdb .Till now i have used the Local
Actually I have a serious problem : I saw that somebody has accessed my
Actually the problem arises since we have named a column authorization which is ok
Actually we have developed java midlet application , that needs to be downloaded through
Actually i am creating an application in which i want to load images from
Actually, I am facing a problem in Android. I am creating an application that
Actually i am working on a image editing software and now i want to
Actually I have retrieved image saved on facebook but i am not getting how
Actually, I want to create an application in C such that 2 people can

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.