Using NotNull() on columns

Topics: Troubleshooting, Writing modules
Feb 25, 2011 at 1:30 PM
Edited Feb 25, 2011 at 1:33 PM

I have created a NotNull column on a content part:

SchemaBuilder.CreateTable("CategoryPartRecord", table => table

		.ContentPartRecord()
		.Column<string>("Name", column => column.NotNull()));

 

However, when I try to create a new record for this part with non-empty Name, I am getting a database exception "cannot insert NULL value in column Name". To make sure it is not connected with my other code, I have removed NotNull specification from this part and recreated the database -- now records are inserted successfully and name is stored OK.

I looked through the existing modules, and it seems that nobody is using NOT NULL columns in tables.

Am I doing something wrong? Or does it mean that we should not use NotNull() for string columns for some reason?

Thanks.

--Daniel

Coordinator
Feb 28, 2011 at 11:55 PM

Can you please file a bug with some simple repro code?

Sep 12, 2011 at 4:32 PM

I have same problem. I've used .NotNull() in content part records. I'm getting "cannot insert NULL" exception when adding content with my part.

Coordinator
Sep 14, 2011 at 10:08 PM

Same answer then :) Please provide simple repro steps and we'll look at it.

Developer
Sep 16, 2011 at 11:19 PM

Had that one also. Have to figure out the exact repro steps.

AFAIR it happened when you created your item, containing a part that has one of the underlying record columns marked as NotNull, and modified that part's properties AFTER the creation (so after calling .Create() on ContentManager - not between .New() and .Create()). It looked like NHibernate is issuing an INSERT statement (with null values), followed by UPDATE (with correct values) instead of a single INSERT.

Sep 23, 2011 at 1:58 PM

I confirm the issue, with the same reproduction steps as pszmyd. It's not a critical bug, but an annoying one: Nothing prevent us from validating our parts beforehand.

Coordinator
Sep 23, 2011 at 6:36 PM

Did anyone file a bug for this?