Why PartRecord couldn't be saved ?

Topics: Writing modules
Apr 2, 2012 at 8:24 AM
Edited Apr 2, 2012 at 8:33 AM


I'm trying to learn how to work with Orchard by writing a simple and useless Widget based on the following PartRecord :

public class TestWidgetPartRecord : ContentPartRecord
    public virtual String Property1 { get; set; }
    public virtual String Property2 { get; set; }

As you can see, a quiet simple model ...

According to this tutorial : http://docs.orchardproject.net/Documentation/Writing-a-widget a made a migration file like this :


public class TestWidgetMigration : DataMigrationImpl
	public Int32 Create()
			t => t.ContentPartRecord()
		               .Column("Property1", DbType.String, c => c.NotNull())
		        	      .Column("Property2", DbType.String, c => c.NotNull())
			b => b.Attachable()
			b => b.WithPart("TestWidgetPart")
				  .WithSetting("Stereotype", "Widget")
		return 1;


When I add the resulting Widget to a zone of the Default layer I have the right confirmation message : "Your Test Widget has been added." But I can't see its reference in widget management screen and the entry is missing in the corresponding table "ModuleName_TestWidgetPartRecord", no error, nothing ...

I've spend few hours and raging a lot on this simple scenario to finaly notice that when I remove the constraint NotNull() in the declaration of the TestWidgetPartRecord table everything works fine.

Why didn't I obtain any error, no warning at all ? I don't understand why my NotNull() constraint provide a wrong model ? What am I doing wrong ?

I would like to notify that it's very difficult to work why this kind of "Everything is fine but nothing works" behaviour  !

Thanks for your answers.

Apr 3, 2012 at 2:15 AM

Nothing even in app_data\logs?

Apr 3, 2012 at 8:20 AM

Thank you for your answer, I moved forward. But next time I'll look at the logs folder, I didn't noticed its presence.



Apr 4, 2012 at 11:49 AM

NotNull seems to be a bit problematic for Records in Orchard as I discovered yesterday (http://orchard.codeplex.com/workitem/18604). If you add a constructor to your Record class that gives the member an initial value, it should work for you.

Apr 5, 2012 at 7:01 PM

Do you have a handler with a storage filter for the record? And do you have a driver? (Part records don't seem to store with out one)

I have seen this and it's usually from one of those 2 things.