Update list in Entity Framework model

Viewed 3333

I have an Entity Framework model:

public class Application
{
    [Key]
    public int ApplicationID { get; set; }
    public int PatentID { get; set; }

    ...

    //------------------------------------
    public string ApplicationNumber { get; set; }
    public string Priority { get; set; }
    public List<ApplicationPayment> Payments { get; set; } 
                          = new List<ApplicationPayment>();
}

and payment's model:

public class ApplicationPayment
{
    [Key]
    public int PaymentID { get; set; }
    public string PaymentName { get; set; }
    public float Amount { get; set; }
    public int PayNumber { get; set; }
    public DateTime Date { get; set; } = new DateTime(2017, 12, 1);
    public float TopicPart { get; set; }
}

Entity Framework creates additional foreign keys for me in ApplicationPayment model Application_ApplicationID.

I add a new instance in ApplicationPayment table that has number of the existing Application:sql models

But when I try to display this ApplicationPayment's table this returns the empty table.

I tried to add ApplicationPayment manually through SQL Server Management Studio and via fake-request. New line added but the list of ApplicationPayment is still empty.

Fake-request:

    [HttpPut]
    public void CreateApplicationPayment(int? id)
    {
        ApplicationPayment appPayment = new ApplicationPayment()
        {
            Amount = 80.0f,
            Date = new DateTime(2017, 10, 25),
            PaymentName = "payment",
            PayNumber = 30,
            TopicPart = 20
        };

        Application application = db.Applications.Find(id);

        application.Payments.Add(appPayment);
        db.SaveChanges();

    }
1 Answers
Related