示例#1
0
        public void SaveChildObjects(pileEntities db)
        {
            foreach (var address in Addresses.Where(x => x.Id != 0))
            {
                db.Entry(address).State = EntityState.Modified;
            }
            foreach (var email in EmailAddresses.Where(x => x.Id != 0))
            {
                db.Entry(email).State = EntityState.Modified;
            }
            foreach (var note in Notes.Where(x => x.Id != 0))
            {
                db.Entry(note).State = EntityState.Modified;
            }
            foreach (var phone in Phones.Where(x => x.Id != 0))
            {
                db.Entry(phone).State = EntityState.Modified;
            }


            foreach (var address in Addresses.Where(x => x.Id == 0))
            {
                db.Addresses.Add(address);
            }
            foreach (var email in EmailAddresses.Where(x => x.Id == 0))
            {
                db.EmailAddresses.Add(email);
            }
            foreach (var note in Notes.Where(x => x.Id == 0))
            {
                db.Notes.Add(note);
            }
            foreach (var phone in Phones.Where(x => x.Id == 0))
            {
                db.Phones.Add(phone);
            }

            db.SaveChanges();
        }