R
R
reboot7772019-06-24 07:48:26
ASP.NET
reboot777, 2019-06-24 07:48:26

Adding entries to add. a table that has a relationship with the main table?

Hi all. I am writing a project using asp.net mvc.
1. I have implemented a connection between the main table and additional. table.
2. People table. Columns: id, name.
3. Treatment table. Columns: id_chelovek, data, prichina_obraschenia, mark o vipolnenii.
3. Created a link between id and id_chelovek. In order for records of the Treatment table to cling to one person.
5. Added People controller, view. Next, I created a partial Treatment clause and embedded it into the People view.
4. The problem is that when checking the addition of records, it adds only id, name. A record in the Treatment table for the same person is not added. And it is necessary that when I add information about a person, I can add several treatments for the same person in the same view at the same time.
Now the questions are:
1. What is the problem? Why is it not added?
2. How to implement this in an asp.net application using c#?
Thank you for your attention.
PS detailed answer please.
3.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fat Lorrie, 2019-06-24
@reboot777

var newPerson = new People {
   //Id = model.Id,
   Name = model.Name,
   Treatment = new Treatment {
        //...
   },
};

dbCcontext.People.Add(newPerson);
dbCcontext.SaveChanges();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question