Thunderstruck
Thunderstruck copied to clipboard
Guid for Primary Key
Hi
I am trying to use the DataObject to insert a row into a table that has a Guid PK. It works great with an incrementing Id. But once I switched to a Guid I can't get it to work. I've tried setting the pk like this in the initialisation:
var userData = new DataObject<Users>("Users","Guid"); model.Guid = Guid.NewGuid(); userData.Insert(model);
But that doesn't work I get a sql error saying Guid cannot be null.
"Cannot insert the value NULL into column 'Guid', table 'Nancy.dbo.Users'; column does not allow nulls. INSERT fails."
What am I doing wrong?
Gus
ps: I found this code in DataRuntimeObject.cs which looks a bit dubious. See the "Id" bit.
public PropertyInfo GetPrimaryKey(string primaryKeyName) { if (_primaryKey == null) { var validProperties = GetValidProperties(); if (primaryKeyName != null) return validProperties.FirstOrDefault(p => p.Name == primaryKeyName); _primaryKey = validProperties.FirstOrDefault(p => p.Name == "Id" ) ?? validProperties.First(); }
return _primaryKey;
}
As far as I know, Thunderstruck only supports integer primary key fields using IDENTITY columns.
yes, thanks, it would be nice if it could handle GUID's because IDENTITY types are troublesome for me when it comes to merging databases. But I don't have a good enough grasp of the code to be able to enhance it.