简体   繁体   中英

CRUD one-to-one relationship inserting data

I have a really simple two tables made with code-first approach with relationship one to one. I do not know what is the best way to insert data.

Since each trip has one coach should I have two CRUD pages one for trips one for coaches? But then would I need another page to link them up together?

What I'm asking is: is there a way to make on one CRUD page eg when creating a trip to add a coach to it.

public class Coach
    {
        public int CoachID { get; set; }
        public int Capacity { get; set; }

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

public class Trip
    {
        public int TripID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

        public List<Ticket> Tickets { get; set; }
        public Coach Coach { get; set; }

    }

The issue that I'm facing right now is after adding trip I'm going to add a coach which has a dropdown to select for which trip do I want to add this coach and pressing create does nothing the page just stays the same nothing happens. 增加行程 添加教练

I would usually create method that are simple, does only one thing.

I would create two simple CRUD for both and have another service method that calls both 'Create' for Coach and 'Create' for Trip.

Make sure that each form is actually wrapped in a form tag and that your buttons type is "submit". This should at least get you to your next step of figuring out how you would like to implement it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM