EF Code-first multipicity constraint violated when looping over import files
===

<!-- language-all: lang-cs -->

I have a `ParentObject` and `ChildObject` class in a C# Code-First EF model:

    //attributes are set as appropriate
	public class ParentObject{
		public int Key{get; set;}
		public string Name {get; set;}
		public HashSet<ChildObject> TheChildren {get; set;}
	}

	public class ChildObject{
		public int Key {get; set;}
		public int ParentKey {get; set;}
		string ParentName {get; set;}
		public string Name {get; set;}
	}

	 public class FamilyDB : DbContext{
		public DbSet<ParentObject> Parents { get; set; } 
		public DbSet<ChildObject> Children { get; set; }
		
		public FamilyDB(): base(){
			this.Parents.Load(); this.Children.Load();
		}
	}

I'd like to populate a `FamilyDB` database from a set of CSV files. The `Parents` already exist; I just need to overwrite and assign `TheChildren` for each `ParentObject`.

For a single CSV file, my code, as follows, works fine:

	public static void ImportChildFile(FamilyDB connxn, string csvPath){
		List<ChildObject> records = GetChildrenFromCsvFile(csvPath);
		var groupedRecords = records.GroupBy(x => x.ParentName);
		
		foreach (var recordSet in groupedRecords){
			parentName = recordSet.Key;
			ParentObject matchingParent = connxn.Parents.FindFirstByName(parentName);

			if (matchingParent == null)
				throw new ArgumentException("No prnt named " + parentName);

            //Want to overwrite, not add - must remove all current children
			while (matchingParent.Children.Count > 0)
				connxn.TheChildren.Remove(matchingParent.Children.Last());
		
			matchingParent.TheChildren.UnionWith(recordSet);
		}
	}

The problem comes when saving: Saving the changes after a single CSV file import works fine, but not when I have imported multiple files between saves - even if there is no `ParentName` overlap between the encoded `ChildObject`s:

	private static void Main()
	{
		FamilyDB connxn = new FamilyDB();
		FileInfo[] myCSVFiles; //defined elsewhere, has two members
		foreach (FileInfo file in myCSVFiles}{
			ImportChildFile(connxn, file.FullName);
			//connxn.SaveChanges(); //this would work if it was here
		}
		connxn.SaveChanges();

        /*Multiplicity constraint violated. 
        The role 'ParentObject_Children_Source' of 
        the relationship 'MyNamespace.ParentObject_Children' 
        has multiplicity 1 or 0..1.*/
	} 

That error message seems to accuse me of assigning to `TheChildren` twice, but I did no such thing - like I said, there's no overlap in CSV files. So what did I do wrong, and how can I fix it?