unable to save child entity that inherits (code-first)

Oct 18, 2011 at 8:11 AM

Congratulations on the open source release. Things are going well with the nuget delivered goodness.

I'm using code-first with table-per-type and have classes Party<=Person and Note<=PartyNote (Party and Note are abstract). When adding a PartyNote to a Person using the following method, an exception [ArgumentException: An entry must be provided] is thrown from the GenericController.Edit action method when the subsequent view is filled out and saved.

On Party:

public PartyNote AddNote()
	var partyNote = Container.NewTransientInstance<PartyNote>();
	partyNote.Party = this;
	return partyNote;

private ICollection<PartyNote> _notes = new List<PartyNote>();

public virtual ICollection<PartyNote> Notes
	get { return _notes; }
	set { _notes = value; }


public abstract class Note
	public virtual int NoteId { get; set; }

	public virtual DateTime NoteDate { get; set; }

	public virtual DateTime DefaultNoteDate()
		return DateTime.Now;

	public virtual string NoteBody { get; set; }


public class PartyNote : Note
	public virtual Party Party { get; set; }

Any ideas what I might be doing wrong? This method for adding child records works for other non-inheriting child records.


Oct 18, 2011 at 8:59 AM


You're not doing anything wrong  -  I'm pretty sure you've hit the same bug in the framework that was reported yesterday.  See http://nakedobjects.codeplex.com/workitem/3  The problem is caused by having a child object whose type name is just an extended version of the Parent (not superclass) name i.e. Party and PartyNote

Please note that we fixed this bug yesterday in the source, in the repository, but not re-released yet.  Your options are:

- Check out the source and re-build the framework yourself.  (Stef will very shortly be posting some notes to make it clearer how to build the framework  -  it's not difficult but you do need the pre-requisites in place.)
- Wait for new release.  That might be a few days yet.
- Workaround by changing the name of your PartyNote class to e.g. NoteToParty.  N.B. the Note > NoteToParty shouldn't cause a problem, because that is an inheritance not a composition relationship.


Oct 18, 2011 at 3:08 PM

Hi Richard,

Thanks for the quick response as always!

I renamed the child class as you suggested and the save works. I'll go with this solution for now as I have a deadline to get through.

I do want to check out the source and build myself eventually so I can better understand the internals of the framework. I'll keep an eye out for the build notes.


Oct 18, 2011 at 4:26 PM


Please note that we have now made a new release  -  so just do an update via NuGet. 

 If you (separately) decide to download the new release of the source, you'll find it contains a new HowToBuild.txt file.