There is a database with related tables. Entity Framework Code First
Table 1.
public class Student { public Student() { CourseWork = new ObservableCollection<CourseWork>(); StateAtt = new ObservableCollection<StateAttestation>(); AddInfo = new ObservableCollection<AdditionalInformation>(); Practice = new ObservableCollection<Practice>(); Discipline = new ObservableCollection<Discipline>(); Electives = new ObservableCollection<Electives>(); } private ObservableCollection<CourseWork> _courseWork; private ObservableCollection<StateAttestation> _stateAtt; private ObservableCollection<AdditionalInformation> _addInfo; private ObservableCollection<Practice> _practice; private ObservableCollection<Discipline> _discipline; private ObservableCollection<Electives> _electives; public virtual ObservableCollection<CourseWork> CourseWork { get { return _courseWork; } set { _courseWork = value; } } public virtual ObservableCollection<StateAttestation> StateAtt { get { return _stateAtt; } set { _stateAtt = value; } } public virtual ObservableCollection<AdditionalInformation> AddInfo { get { return _addInfo; } set { _addInfo = value; } } public virtual ObservableCollection<Practice> Practice { get { return _practice; } set { _practice = value; } } public virtual ObservableCollection<Discipline> Discipline { get { return _discipline; } set { _discipline = value; } } public virtual ObservableCollection<Electives> Electives { get { return _electives; } set { _electives = value; } } [Key] public int StudentID { get; set; } [Required] public string FullName { get; set; } [Required] public DateTime BirthDate { get; set; } [MaxLength(265)] public string PreviousLevelEducation { get; set; } public int RegistrationNumber { get; set; } [Required] public DateTime ExtraditionDate { get; set; } [Required] public bool ExcellentAttribute { get; set; } [Required] public int DiplomSeries { get; set; } [Required] public int DiplomNumber { get; set; } [Required] public int AttachmentSeries { get; set; } [Required] public int AttachmentNumber { get; set; } [Required] public DateTime DecisionDate { get; set; } [Required] public string Qualification { get; set; } [Required] public string Specialty { get; set; } [Required] public string Lifetime { get; set; } } Table 2.
public class Discipline { [Key] public int DisciplineID { get; set; } [Required] public string DisciplineName { get; set; } [Required] public int QuantityHours { get; set; } [InverseProperty("Discipline")] public virtual Student discipline { get; set; } [Required] public string Rating { get; set; } } How to implement copying a row from the main (table 1) and all related rows from table 2 and the rest? I understand that you need to replace all the keys, but I haven’t found any implementation on the Internet. (Copy to the same tables, but with different id)
Копировать в те же таблицы, но с другими idis an important remark to add to the question! - Bulson