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

Oct 18, 2011 at 7: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; }
}

Note:

[Table("Note")]
public abstract class Note
{
	[Hidden]
	public virtual int NoteId { get; set; }

	[Title]
	public virtual DateTime NoteDate { get; set; }

	
	public virtual DateTime DefaultNoteDate()
	{
		return DateTime.Now;
	}

	public virtual string NoteBody { get; set; }
}

PartyNote:

[Table("PartyNote")]
public class PartyNote : Note
{
	[Disabled]
	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.

Thanks,
-Brian 

Coordinator
Oct 18, 2011 at 7:59 AM

Brian

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.

Richard

Oct 18, 2011 at 2: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.

-Brian

Coordinator
Oct 18, 2011 at 3:26 PM

Brian

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.

Richard