PetaPoco fails to insert Guid.NewGuid()


Story by Abhilash on Umbraco

Share   

Last day, I was trying to insert a record to one of the table in Umbraco v7, using PetaPOCO, where PrimaryKey is of type uniqueidentifier (guid). To my surprise, the insert operation resulted in an error - "Error: Cannot insert the value NULL into column 'Id', table 'TABLE_NAME'; column does not allow nulls. INSERT fails. The statement has been terminated."; even though primary key is being populated through the code. 

var newItem = new MyModelClass()
{
	Id = Guid.NewGuid(),
	//
	// Other property field follows...
	//
};

db.Insert(newItem);

 This got fixed by using alternate method signature as below: 

db.Insert("TableName", "id", false, newItem);

 Hope this helps.





comments powered by Disqus

Related Story   →

Fix: HTML5 Video not playing when deployed to azure

A post on how to playback HTML5 video when published to Azure.